## START: Set by rpmautospec
## (rpmautospec version 0.3.0)
%define autorelease(e:s:pb:n) %{?-p:0.}%{lua:
    release_number = 7;
    base_release_number = tonumber(rpm.expand("%{?-b*}%{!?-b:1}"));
    print(release_number + base_release_number - 1);
}%{?-e:.%{-e*}}%{?-s:.%{-s*}}%{!?-n:%{?dist}}
## END: Set by rpmautospec

# Generated by go2rpm 1.6.0
%bcond_without check
# toggle to check if failing tests now pass
%bcond_with all_tests

# https://github.com/ent/ent
%global goipath         entgo.io/ent
%global forgeurl        https://github.com/ent/ent
Version:                0.10.0

%gometa

# this was previously golang-github-facebook-ent
%global goaltipaths     github.com/facebook/ent

%global common_description %{expand:
An entity framework for Go.}

%global golicenses      LICENSE
%global godocs          doc examples README.md README_jp.md\\\
                        CODE_OF_CONDUCT.md CONTRIBUTING.md README_zh.md\\\
                        entc/integration/README.md doc

Name:           %{goname}
Release:        %autorelease
Summary:        An entity framework for Go

# Upstream license specification: Apache-2.0
License:        ASL 2.0
URL:            %{gourl}
Source:         %{gosource}

# multiple tests have 32-bit issues, upstream does not test on it
ExcludeArch:    %{arm32} %{ix86}

BuildRequires:  golang(github.com/go-openapi/inflect)
BuildRequires:  golang(github.com/google/uuid)
BuildRequires:  golang(github.com/gorilla/websocket)
BuildRequires:  golang(github.com/json-iterator/go)
BuildRequires:  golang(github.com/mattn/go-sqlite3)
BuildRequires:  golang(github.com/mitchellh/mapstructure)
BuildRequires:  golang(github.com/modern-go/reflect2)
BuildRequires:  golang(github.com/olekukonko/tablewriter)
BuildRequires:  golang(github.com/pkg/errors)
BuildRequires:  golang(github.com/spf13/cobra)
BuildRequires:  golang(go.opencensus.io/stats)
BuildRequires:  golang(go.opencensus.io/stats/view)
BuildRequires:  golang(go.opencensus.io/tag)
BuildRequires:  golang(go.opencensus.io/trace)
BuildRequires:  golang(golang.org/x/sync/errgroup)
BuildRequires:  golang(golang.org/x/sync/semaphore)
BuildRequires:  golang(golang.org/x/tools/go/packages)
BuildRequires:  golang(golang.org/x/tools/imports)

%if %{with check}
# Tests
BuildRequires:  golang(github.com/DATA-DOG/go-sqlmock)
BuildRequires:  golang(github.com/jessevdk/go-flags)
BuildRequires:  golang(github.com/json-iterator/go)
BuildRequires:  golang(github.com/stretchr/testify/assert)
BuildRequires:  golang(github.com/stretchr/testify/mock)
BuildRequires:  golang(github.com/stretchr/testify/require)
BuildRequires:  golang(golang.org/x/tools/go/packages/packagestest)
%endif

# manually-added BRs
BuildRequires:  golang(ariga.io/atlas/sql/migrate)
BuildRequires:  golang(ariga.io/atlas/sql/mysql)
BuildRequires:  golang(ariga.io/atlas/sql/postgres)
BuildRequires:  golang(ariga.io/atlas/sql/schema)
BuildRequires:  golang(ariga.io/atlas/sql/sqlite)


%description
%{common_description}

%gopkg

%prep
%goprep
# rename integration doc to avoid name clash
mv entc/integration/README.md entc/integration/README-integration.md

%generate_buildrequires

%build
for cmd in cmd/ent* ; do
  %gobuild -o %{gobuilddir}/bin/$(basename $cmd) %{goipath}/$cmd
done

%install
%gopkginstall
install -m 0755 -vd                     %{buildroot}%{_bindir}
install -m 0755 -vp %{gobuilddir}/bin/* %{buildroot}%{_bindir}/

%if %{with check}
%check
%if %{without all_tests}
# remove failing tests
# --- FAIL: TestSnapshot_Restore (0.61s)
#     snapshot_test.go:21: Running snapshot-restore integration test
#     snapshot_test.go:43:
#                 Error Trace:    snapshot_test.go:43
#                 Error:          Received unexpected error:
#                                 exit status 1
#                 Test:           TestSnapshot_Restore
# FAIL
# exit status 1
# FAIL    entgo.io/ent/entc/internal      0.625s
rm entc/internal/snapshot_test.go
# --- FAIL: TestLoad (0.23s)
#     load_test.go:18:
#                 Error Trace:    load_test.go:18
#                 Error:          Received unexpected error:
#                                 entc/load: .entc/entc___builddir_build_BUILD_ent-0.10.0__build_src_entgo.io_ent_entc_load_testdata_valid_1652380697.go:16:2: cannot find package "_/builddir/build/BUILD/ent-0.10.0/_build/src/entgo.io/ent/entc/load/testdata/valid" in any of:
#                                         /usr/lib/golang/src/_/builddir/build/BUILD/ent-0.10.0/_build/src/entgo.io/ent/entc/load/testdata/valid (from $GOROOT)
#                                         /builddir/build/BUILD/ent-0.10.0/_build/src/_/builddir/build/BUILD/ent-0.10.0/_build/src/entgo.io/ent/entc/load/testdata/valid (from $GOPATH)
#                                         /usr/share/gocode/src/_/builddir/build/BUILD/ent-0.10.0/_build/src/entgo.io/ent/entc/load/testdata/valid
#                 Test:           TestLoad
# --- FAIL: TestLoadSpecific (0.13s)
#     load_test.go:37:
#                 Error Trace:    load_test.go:37
#                 Error:          Received unexpected error:
#                                 entc/load: .entc/entc___builddir_build_BUILD_ent-0.10.0__build_src_entgo.io_ent_entc_load_testdata_valid_1652380697.go:16:2: cannot find package "_/builddir/build/BUILD/ent-0.10.0/_build/src/entgo.io/ent/entc/load/testdata/valid" in any of:
#                                         /usr/lib/golang/src/_/builddir/build/BUILD/ent-0.10.0/_build/src/entgo.io/ent/entc/load/testdata/valid (from $GOROOT)
#                                         /builddir/build/BUILD/ent-0.10.0/_build/src/_/builddir/build/BUILD/ent-0.10.0/_build/src/entgo.io/ent/entc/load/testdata/valid (from $GOPATH)
#                                         /usr/share/gocode/src/_/builddir/build/BUILD/ent-0.10.0/_build/src/entgo.io/ent/entc/load/testdata/valid
#                 Test:           TestLoadSpecific
# --- FAIL: TestLoadBaseSchema (0.21s)
#     load_test.go:60:
#                 Error Trace:    load_test.go:60
#                 Error:          Received unexpected error:
#                                 entc/load: .entc/entc___builddir_build_BUILD_ent-0.10.0__build_src_entgo.io_ent_entc_load_testdata_base_1652380698.go:16:2: cannot find package "_/builddir/build/BUILD/ent-0.10.0/_build/src/entgo.io/ent/entc/load/testdata/base" in any of:
#                                         /usr/lib/golang/src/_/builddir/build/BUILD/ent-0.10.0/_build/src/entgo.io/ent/entc/load/testdata/base (from $GOROOT)
#                                         /builddir/build/BUILD/ent-0.10.0/_build/src/_/builddir/build/BUILD/ent-0.10.0/_build/src/entgo.io/ent/entc/load/testdata/base (from $GOPATH)
#                                         /usr/share/gocode/src/_/builddir/build/BUILD/ent-0.10.0/_build/src/entgo.io/ent/entc/load/testdata/base
#                 Test:           TestLoadBaseSchema
# FAIL
# exit status 1
# FAIL    entgo.io/ent/entc/load  1.099s
rm entc/load/load_test.go
%endif
%gocheck
%endif

%files
%license LICENSE
%doc doc examples README.md README_jp.md CODE_OF_CONDUCT.md CONTRIBUTING.md
%doc README_zh.md entc/integration/README-integration.md doc
%{_bindir}/*

%gopkgfiles

%changelog
* Wed Aug 10 2022 Maxwell G <gotmax@e.email> 0.10.0-7
- Rebuild to fix FTBFS

* Thu Jul 21 2022 Fedora Release Engineering <releng@fedoraproject.org> 0.10.0-6
- Rebuilt for https://fedoraproject.org/wiki/Fedora_37_Mass_Rebuild

* Tue Jul 19 2022 Maxwell G <gotmax@e.email> 0.10.0-5
- Rebuild for
  CVE-2022-{1705,32148,30631,30633,28131,30635,30632,30630,1962} in golang

* Sat Jun 18 2022 Robert-André Mauchin <zebob.m@gmail.com> 0.10.0-4
- Rebuilt for CVE-2022-1996, CVE-2022-24675, CVE-2022-28327,
  CVE-2022-27191, CVE-2022-29526, CVE-2022-30629

* Fri Jun 17 2022 Robert-André Mauchin <zebob.m@gmail.com> 0.10.0-3
- Rebuilt for CVE-2022-1996, CVE-2022-24675, CVE-2022-28327,
  CVE-2022-27191, CVE-2022-29526, CVE-2022-30629

* Thu May 12 2022 Michel Alexandre Salim <salimma@fedoraproject.org> 0.10.0-2
- Also exclude 32-bit ARM

* Thu May 12 2022 Michel Alexandre Salim <salimma@fedoraproject.org> 0.10.0-1
- Initial Fedora package