From aab761ac8a42632f1630400c03cb16d0d2cf79d5 Mon Sep 17 00:00:00 2001 From: wang yan Date: Wed, 29 Aug 2018 11:49:55 +0800 Subject: [PATCH] Fix gofmt check results Signed-off-by: wang yan --- src/adminserver/api/cfg_test.go | 2 +- src/adminserver/api/monitor.go | 2 +- src/adminserver/api/monitor_test.go | 13 +-- src/adminserver/api/systeminfo_test.go | 2 +- src/adminserver/auth/auth_test.go | 2 +- src/adminserver/client/client_test.go | 2 +- src/adminserver/handlers/handler.go | 8 +- src/adminserver/handlers/handlers_test.go | 20 ++-- src/adminserver/handlers/router.go | 2 +- .../systemcfg/encrypt/encrypt_test.go | 2 +- .../store/database/driver_db_test.go | 2 +- src/adminserver/systemcfg/systemcfg_test.go | 2 +- .../imagestorage/filesystem/driver_test.go | 2 +- src/common/dao/admin_job_test.go | 2 +- src/common/dao/dao_test.go | 6 +- src/common/dao/group/usergroup_test.go | 6 +- src/common/dao/pgsql.go | 2 +- src/common/dao/pro_meta_test.go | 2 +- src/common/dao/project/projectmember_test.go | 4 +- src/common/dao/repository_test.go | 4 +- src/common/dao/resource_label_test.go | 4 +- src/common/dao/user_test.go | 2 +- src/common/dao/watch_item_test.go | 2 +- src/common/http/modifier/auth/auth_test.go | 2 +- src/common/job/client_test.go | 2 +- .../admiral/authcontext/authcontext_test.go | 6 +- src/common/security/local/context_test.go | 8 +- src/common/security/secret/context_test.go | 2 +- src/common/utils/clair/client_test.go | 2 +- src/common/utils/clair/utils_test.go | 2 +- src/common/utils/ldap/ldap_test.go | 4 +- src/common/utils/notary/helper.go | 2 +- src/common/utils/notary/helper_test.go | 2 +- .../registry/auth/tokenauthorizer_test.go | 4 +- src/common/utils/registry/repository_test.go | 4 +- src/common/utils/uaa/client_test.go | 2 +- src/common/utils/uaa/fake_client.go | 4 +- src/jobservice/api/handler_test.go | 2 +- src/jobservice/api/router.go | 2 +- src/jobservice/core/controller.go | 2 +- src/jobservice/core/controller_test.go | 2 +- src/jobservice/job/impl/utils/utils.go | 2 +- src/jobservice/opm/op_commands.go | 2 +- src/jobservice/opm/redis_job_stats_mgr.go | 2 +- .../opm/redis_job_stats_mgr_test.go | 2 +- src/jobservice/period/enqueuer.go | 4 +- src/jobservice/period/redis_scheduler.go | 2 +- src/jobservice/period/sweeper.go | 2 +- src/jobservice/pool/message_server.go | 2 +- src/jobservice/pool/redis_pool.go | 4 +- src/jobservice/runtime/bootstrap.go | 2 +- src/registryctl/auth/secret_test.go | 2 +- src/registryctl/client/client_test.go | 2 +- src/registryctl/handlers/handler.go | 2 +- src/registryctl/handlers/handler_test.go | 2 +- src/registryctl/handlers/router.go | 2 +- src/replication/core/controller_test.go | 18 ++-- .../event/on_deletion_handler_test.go | 2 +- src/replication/event/on_push_handler_test.go | 2 +- .../event/start_replication_handler_test.go | 2 +- src/replication/models/filter_test.go | 22 ++-- src/replication/models/trigger_test.go | 22 ++-- src/replication/policy/manager_test.go | 4 +- .../source/default_filter_chain_test.go | 10 +- src/replication/source/label_filter_test.go | 4 +- src/replication/source/pattern_filter_test.go | 12 +-- .../source/repository_convertor_test.go | 20 ++-- .../source/repository_filter_test.go | 10 +- .../source/tag_combination_filter_test.go | 14 +-- src/replication/source/tag_convertor_test.go | 12 +-- src/replication/source/tag_filter_test.go | 12 +-- src/replication/trigger/immediate_test.go | 4 +- src/replication/trigger/manager_test.go | 4 +- src/replication/trigger/schedule_test.go | 2 +- src/replication/trigger/watch_list_test.go | 4 +- src/ui/api/api_test.go | 4 +- src/ui/api/chart_repository_test.go | 2 +- src/ui/api/config_test.go | 2 +- src/ui/api/label_test.go | 68 ++++++------ src/ui/api/ldap_test.go | 22 ++-- src/ui/api/log_test.go | 4 +- src/ui/api/metadata_test.go | 2 +- src/ui/api/project_test.go | 4 +- src/ui/api/projectmember_test.go | 32 +++--- src/ui/api/reg_gc_test.go | 2 +- src/ui/api/replication_policy_test.go | 102 +++++++++--------- src/ui/api/replication_test.go | 8 +- src/ui/api/repository_label_test.go | 22 ++-- src/ui/api/repository_test.go | 18 ++-- src/ui/api/search_test.go | 4 +- src/ui/api/target_test.go | 2 +- src/ui/api/user_test.go | 22 ++-- src/ui/api/usergroup_test.go | 14 +-- src/ui/auth/auth_test.go | 2 +- src/ui/auth/uaa/uaa_test.go | 2 +- src/ui/config/config_test.go | 2 +- src/ui/controllers/controllers_test.go | 2 +- src/ui/filter/readonly_test.go | 2 +- src/ui/filter/security.go | 8 +- src/ui/filter/security_test.go | 2 +- src/ui/promgr/metamgr/metamgr_test.go | 4 +- .../promgr/pmsdriver/admiral/admiral_test.go | 4 +- src/ui/promgr/pmsdriver/local/local_test.go | 2 +- src/ui/promgr/promgr_test.go | 4 +- src/ui/proxy/interceptor_test.go | 4 +- src/ui/service/notifications/clair/handler.go | 4 +- src/ui/service/token/token_test.go | 38 +++---- 107 files changed, 389 insertions(+), 388 deletions(-) diff --git a/src/adminserver/api/cfg_test.go b/src/adminserver/api/cfg_test.go index 1b0c7bfbd..ef2b6c886 100644 --- a/src/adminserver/api/cfg_test.go +++ b/src/adminserver/api/cfg_test.go @@ -26,9 +26,9 @@ import ( "os" "testing" - "github.com/stretchr/testify/assert" "github.com/goharbor/harbor/src/adminserver/systemcfg" "github.com/goharbor/harbor/src/common" + "github.com/stretchr/testify/assert" ) type fakeCfgStore struct { diff --git a/src/adminserver/api/monitor.go b/src/adminserver/api/monitor.go index fdb090aaf..1555c2964 100644 --- a/src/adminserver/api/monitor.go +++ b/src/adminserver/api/monitor.go @@ -1,8 +1,8 @@ package api import ( - "net/http" "github.com/goharbor/harbor/src/common/utils/log" + "net/http" ) // Ping monitor the server status diff --git a/src/adminserver/api/monitor_test.go b/src/adminserver/api/monitor_test.go index d7536ce52..578fab9f5 100644 --- a/src/adminserver/api/monitor_test.go +++ b/src/adminserver/api/monitor_test.go @@ -1,16 +1,17 @@ package api -import( - "testing" - "net/http/httptest" - "net/http" + +import ( "github.com/stretchr/testify/assert" - "io/ioutil" + "io/ioutil" + "net/http" + "net/http/httptest" + "testing" ) func TestPing(t *testing.T) { w := httptest.NewRecorder() Ping(w, nil) assert.Equal(t, http.StatusOK, w.Code) - result, _:= ioutil.ReadAll(w.Body) + result, _ := ioutil.ReadAll(w.Body) assert.Equal(t, "\"Pong\"", string(result)) } diff --git a/src/adminserver/api/systeminfo_test.go b/src/adminserver/api/systeminfo_test.go index 228f77160..6b858a1b4 100644 --- a/src/adminserver/api/systeminfo_test.go +++ b/src/adminserver/api/systeminfo_test.go @@ -22,8 +22,8 @@ import ( "net/http/httptest" "testing" - "github.com/stretchr/testify/assert" "github.com/goharbor/harbor/src/adminserver/systeminfo/imagestorage" + "github.com/stretchr/testify/assert" ) type fakeImageStorageDriver struct { diff --git a/src/adminserver/auth/auth_test.go b/src/adminserver/auth/auth_test.go index 2e090ef1f..6481bbd85 100644 --- a/src/adminserver/auth/auth_test.go +++ b/src/adminserver/auth/auth_test.go @@ -18,8 +18,8 @@ import ( "net/http" "testing" - "github.com/stretchr/testify/assert" commonsecret "github.com/goharbor/harbor/src/common/secret" + "github.com/stretchr/testify/assert" ) func TestAuthenticate(t *testing.T) { diff --git a/src/adminserver/client/client_test.go b/src/adminserver/client/client_test.go index f3bede97d..6be9f5b6d 100644 --- a/src/adminserver/client/client_test.go +++ b/src/adminserver/client/client_test.go @@ -19,9 +19,9 @@ import ( "os" "testing" - "github.com/stretchr/testify/assert" "github.com/goharbor/harbor/src/common" "github.com/goharbor/harbor/src/common/utils/test" + "github.com/stretchr/testify/assert" ) var c Client diff --git a/src/adminserver/handlers/handler.go b/src/adminserver/handlers/handler.go index 80c3a7e92..3652ef515 100644 --- a/src/adminserver/handlers/handler.go +++ b/src/adminserver/handlers/handler.go @@ -18,9 +18,9 @@ import ( "net/http" "os" - gorilla_handlers "github.com/gorilla/handlers" "github.com/goharbor/harbor/src/adminserver/auth" "github.com/goharbor/harbor/src/common/utils/log" + gorilla_handlers "github.com/gorilla/handlers" ) // NewHandler returns a gorilla router which is wrapped by authenticate handler @@ -32,7 +32,7 @@ func NewHandler() http.Handler { "jobserviceSecret": os.Getenv("JOBSERVICE_SECRET"), } insecureAPIs := map[string]bool{ - "/api/ping":true, + "/api/ping": true, } h = newAuthHandler(auth.NewSecretAuthenticator(secrets), h, insecureAPIs) h = gorilla_handlers.LoggingHandler(os.Stdout, h) @@ -49,7 +49,7 @@ func newAuthHandler(authenticator auth.Authenticator, handler http.Handler, inse return &authHandler{ authenticator: authenticator, handler: handler, - insecureAPIs: insecureAPIs, + insecureAPIs: insecureAPIs, } } @@ -61,7 +61,7 @@ func (a *authHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) { return } - if a.insecureAPIs !=nil && a.insecureAPIs[r.URL.Path] { + if a.insecureAPIs != nil && a.insecureAPIs[r.URL.Path] { if a.handler != nil { a.handler.ServeHTTP(w, r) } diff --git a/src/adminserver/handlers/handlers_test.go b/src/adminserver/handlers/handlers_test.go index b803abbd6..68d023e8e 100644 --- a/src/adminserver/handlers/handlers_test.go +++ b/src/adminserver/handlers/handlers_test.go @@ -20,8 +20,8 @@ import ( "net/http/httptest" "testing" - "github.com/stretchr/testify/assert" "github.com/goharbor/harbor/src/adminserver/auth" + "github.com/stretchr/testify/assert" ) type fakeAuthenticator struct { @@ -50,35 +50,35 @@ func TestNewAuthHandler(t *testing.T) { requestURL string }{ - {nil, nil, nil, http.StatusOK,"http://localhost/good"}, + {nil, nil, nil, http.StatusOK, "http://localhost/good"}, {&fakeAuthenticator{ authenticated: false, err: nil, - }, nil, nil, http.StatusUnauthorized,"http://localhost/hello"}, + }, nil, nil, http.StatusUnauthorized, "http://localhost/hello"}, {&fakeAuthenticator{ authenticated: false, err: errors.New("error"), - }, nil, nil, http.StatusInternalServerError,"http://localhost/hello"}, + }, nil, nil, http.StatusInternalServerError, "http://localhost/hello"}, {&fakeAuthenticator{ authenticated: true, err: nil, - }, &fakeHandler{http.StatusNotFound}, nil, http.StatusNotFound,"http://localhost/notexsit"}, + }, &fakeHandler{http.StatusNotFound}, nil, http.StatusNotFound, "http://localhost/notexsit"}, {&fakeAuthenticator{ authenticated: false, err: nil, - }, &fakeHandler{http.StatusOK},map[string]bool{"/api/ping":true,},http.StatusOK,"http://localhost/api/ping"}, + }, &fakeHandler{http.StatusOK}, map[string]bool{"/api/ping": true}, http.StatusOK, "http://localhost/api/ping"}, } for _, c := range cases { handler := newAuthHandler(c.authenticator, c.handler, c.insecureAPIs) w := httptest.NewRecorder() - r := httptest.NewRequest("GET",c.requestURL,nil) + r := httptest.NewRequest("GET", c.requestURL, nil) handler.ServeHTTP(w, r) assert.Equal(t, c.responseCode, w.Code, "unexpected response code") } handler := NewHandler() w := httptest.NewRecorder() - r := httptest.NewRequest("GET","http://localhost/api/ping",nil) - handler.ServeHTTP(w,r) - + r := httptest.NewRequest("GET", "http://localhost/api/ping", nil) + handler.ServeHTTP(w, r) + } diff --git a/src/adminserver/handlers/router.go b/src/adminserver/handlers/router.go index 3a32d8834..d46e27f16 100644 --- a/src/adminserver/handlers/router.go +++ b/src/adminserver/handlers/router.go @@ -17,8 +17,8 @@ package handlers import ( "net/http" - "github.com/gorilla/mux" "github.com/goharbor/harbor/src/adminserver/api" + "github.com/gorilla/mux" ) func newRouter() http.Handler { diff --git a/src/adminserver/systemcfg/encrypt/encrypt_test.go b/src/adminserver/systemcfg/encrypt/encrypt_test.go index 7c0c283ad..3d1487edc 100644 --- a/src/adminserver/systemcfg/encrypt/encrypt_test.go +++ b/src/adminserver/systemcfg/encrypt/encrypt_test.go @@ -18,8 +18,8 @@ import ( "errors" "testing" - "github.com/stretchr/testify/assert" comcfg "github.com/goharbor/harbor/src/common/config" + "github.com/stretchr/testify/assert" ) type fakeKeyProvider struct { diff --git a/src/adminserver/systemcfg/store/database/driver_db_test.go b/src/adminserver/systemcfg/store/database/driver_db_test.go index 75d2cd7b9..00970e5ac 100644 --- a/src/adminserver/systemcfg/store/database/driver_db_test.go +++ b/src/adminserver/systemcfg/store/database/driver_db_test.go @@ -3,9 +3,9 @@ package database import ( "testing" - "github.com/stretchr/testify/assert" "github.com/goharbor/harbor/src/common" "github.com/goharbor/harbor/src/common/models" + "github.com/stretchr/testify/assert" ) func TestCfgStore_Name(t *testing.T) { diff --git a/src/adminserver/systemcfg/systemcfg_test.go b/src/adminserver/systemcfg/systemcfg_test.go index 2be9eeabd..70c036f19 100644 --- a/src/adminserver/systemcfg/systemcfg_test.go +++ b/src/adminserver/systemcfg/systemcfg_test.go @@ -18,8 +18,8 @@ import ( "os" "testing" - "github.com/stretchr/testify/assert" "github.com/goharbor/harbor/src/common" + "github.com/stretchr/testify/assert" ) func TestParseStringToInt(t *testing.T) { diff --git a/src/adminserver/systeminfo/imagestorage/filesystem/driver_test.go b/src/adminserver/systeminfo/imagestorage/filesystem/driver_test.go index e72ef13d0..e1a503dd1 100644 --- a/src/adminserver/systeminfo/imagestorage/filesystem/driver_test.go +++ b/src/adminserver/systeminfo/imagestorage/filesystem/driver_test.go @@ -17,8 +17,8 @@ package filesystem import ( "testing" - "github.com/stretchr/testify/assert" storage "github.com/goharbor/harbor/src/adminserver/systeminfo/imagestorage" + "github.com/stretchr/testify/assert" ) func TestName(t *testing.T) { diff --git a/src/common/dao/admin_job_test.go b/src/common/dao/admin_job_test.go index 96143b466..f0575b19c 100644 --- a/src/common/dao/admin_job_test.go +++ b/src/common/dao/admin_job_test.go @@ -17,9 +17,9 @@ package dao import ( "testing" + "github.com/goharbor/harbor/src/common/models" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" - "github.com/goharbor/harbor/src/common/models" ) func TestAddAdminJob(t *testing.T) { diff --git a/src/common/dao/dao_test.go b/src/common/dao/dao_test.go index 1b3c30849..497bb23eb 100644 --- a/src/common/dao/dao_test.go +++ b/src/common/dao/dao_test.go @@ -20,12 +20,12 @@ import ( "time" "github.com/astaxie/beego/orm" - "github.com/stretchr/testify/assert" - "github.com/stretchr/testify/require" "github.com/goharbor/harbor/src/common" "github.com/goharbor/harbor/src/common/models" "github.com/goharbor/harbor/src/common/utils" "github.com/goharbor/harbor/src/common/utils/log" + "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/require" ) func execUpdate(o orm.Ormer, sql string, params ...interface{}) error { @@ -1311,7 +1311,7 @@ func TestImgScanOverview(t *testing.T) { comp := &models.ComponentsOverview{ Total: 2, Summary: []*models.ComponentsOverviewEntry{ - &models.ComponentsOverviewEntry{ + { Sev: int(models.SevMedium), Count: 2, }, diff --git a/src/common/dao/group/usergroup_test.go b/src/common/dao/group/usergroup_test.go index 23a5f7662..ffd005f33 100644 --- a/src/common/dao/group/usergroup_test.go +++ b/src/common/dao/group/usergroup_test.go @@ -251,17 +251,17 @@ func TestOnBoardUserGroup(t *testing.T) { func TestGetGroupDNQueryCondition(t *testing.T) { userGroupList := []*models.UserGroup{ - &models.UserGroup{ + { GroupName: "sample1", GroupType: 1, LdapGroupDN: "cn=sample1_users,ou=groups,dc=example,dc=com", }, - &models.UserGroup{ + { GroupName: "sample2", GroupType: 1, LdapGroupDN: "cn=sample2_users,ou=groups,dc=example,dc=com", }, - &models.UserGroup{ + { GroupName: "sample3", GroupType: 0, LdapGroupDN: "cn=sample3_users,ou=groups,dc=example,dc=com", diff --git a/src/common/dao/pgsql.go b/src/common/dao/pgsql.go index c637bc3bc..6086225b7 100644 --- a/src/common/dao/pgsql.go +++ b/src/common/dao/pgsql.go @@ -23,9 +23,9 @@ import ( _ "github.com/golang-migrate/migrate/database/postgres" //import pgsql driver for migrator _ "github.com/golang-migrate/migrate/source/file" // import local file driver for migrator - _ "github.com/lib/pq" //register pgsql driver "github.com/goharbor/harbor/src/common/utils" "github.com/goharbor/harbor/src/common/utils/log" + _ "github.com/lib/pq" //register pgsql driver ) const defaultMigrationPath = "migrations/postgresql/" diff --git a/src/common/dao/pro_meta_test.go b/src/common/dao/pro_meta_test.go index 5a5dfcdfc..e1ced765e 100644 --- a/src/common/dao/pro_meta_test.go +++ b/src/common/dao/pro_meta_test.go @@ -17,9 +17,9 @@ package dao import ( "testing" + "github.com/goharbor/harbor/src/common/models" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" - "github.com/goharbor/harbor/src/common/models" ) func TestProMetaDaoMethods(t *testing.T) { diff --git a/src/common/dao/project/projectmember_test.go b/src/common/dao/project/projectmember_test.go index 336ed0363..c08039ea5 100644 --- a/src/common/dao/project/projectmember_test.go +++ b/src/common/dao/project/projectmember_test.go @@ -237,7 +237,7 @@ func TestGetProjectMember(t *testing.T) { t.Errorf("Error occurred when GetProjectByName: %v", err) } var memberList1 = []*models.Member{ - &models.Member{ + { ID: 346, Entityname: "admin", Rolename: "projectAdmin", @@ -246,7 +246,7 @@ func TestGetProjectMember(t *testing.T) { EntityType: "u"}, } var memberList2 = []*models.Member{ - &models.Member{ + { ID: 398, Entityname: "test_group_01", Rolename: "projectAdmin", diff --git a/src/common/dao/repository_test.go b/src/common/dao/repository_test.go index 251ae7f33..764dbf3d3 100644 --- a/src/common/dao/repository_test.go +++ b/src/common/dao/repository_test.go @@ -18,10 +18,10 @@ import ( "fmt" "testing" - "github.com/stretchr/testify/assert" - "github.com/stretchr/testify/require" "github.com/goharbor/harbor/src/common" "github.com/goharbor/harbor/src/common/models" + "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/require" ) var ( diff --git a/src/common/dao/resource_label_test.go b/src/common/dao/resource_label_test.go index 8e0e926f8..6bbbc211b 100644 --- a/src/common/dao/resource_label_test.go +++ b/src/common/dao/resource_label_test.go @@ -17,10 +17,10 @@ package dao import ( "testing" - "github.com/stretchr/testify/assert" - "github.com/stretchr/testify/require" "github.com/goharbor/harbor/src/common" "github.com/goharbor/harbor/src/common/models" + "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/require" ) func TestMethodsOfResourceLabel(t *testing.T) { diff --git a/src/common/dao/user_test.go b/src/common/dao/user_test.go index 4a710f13f..064377c53 100644 --- a/src/common/dao/user_test.go +++ b/src/common/dao/user_test.go @@ -18,8 +18,8 @@ import ( "fmt" "testing" - "github.com/stretchr/testify/assert" "github.com/goharbor/harbor/src/common/models" + "github.com/stretchr/testify/assert" ) func TestDeleteUser(t *testing.T) { diff --git a/src/common/dao/watch_item_test.go b/src/common/dao/watch_item_test.go index 6e9087923..1b94e83cb 100644 --- a/src/common/dao/watch_item_test.go +++ b/src/common/dao/watch_item_test.go @@ -17,9 +17,9 @@ package dao import ( "testing" + "github.com/goharbor/harbor/src/common/models" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" - "github.com/goharbor/harbor/src/common/models" ) func TestMethodsOfWatchItem(t *testing.T) { diff --git a/src/common/http/modifier/auth/auth_test.go b/src/common/http/modifier/auth/auth_test.go index 01651626e..f9d1225b7 100644 --- a/src/common/http/modifier/auth/auth_test.go +++ b/src/common/http/modifier/auth/auth_test.go @@ -17,9 +17,9 @@ import ( "net/http" "testing" + commonsecret "github.com/goharbor/harbor/src/common/secret" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" - commonsecret "github.com/goharbor/harbor/src/common/secret" ) func TestAuthorizeOfSecretAuthorizer(t *testing.T) { diff --git a/src/common/job/client_test.go b/src/common/job/client_test.go index 821300af1..b1837cd5a 100644 --- a/src/common/job/client_test.go +++ b/src/common/job/client_test.go @@ -1,9 +1,9 @@ package job import ( - "github.com/stretchr/testify/assert" "github.com/goharbor/harbor/src/common/job/models" "github.com/goharbor/harbor/src/common/job/test" + "github.com/stretchr/testify/assert" "os" "testing" ) diff --git a/src/common/security/admiral/authcontext/authcontext_test.go b/src/common/security/admiral/authcontext/authcontext_test.go index d0b417fe0..4b90e4d74 100644 --- a/src/common/security/admiral/authcontext/authcontext_test.go +++ b/src/common/security/admiral/authcontext/authcontext_test.go @@ -41,7 +41,7 @@ func TestIsSysAdmin(t *testing.T) { func TestGetProjectRoles(t *testing.T) { ctx := &AuthContext{ Projects: []*project{ - &project{ + { Name: "project", Roles: []string{projectAdminRole, developerRole, guestRole}, Properties: map[string]string{"__projectIndex": "9"}, @@ -61,11 +61,11 @@ func TestGetProjectRoles(t *testing.T) { func TestGetMyProjects(t *testing.T) { ctx := &AuthContext{ Projects: []*project{ - &project{ + { Name: "project1", Roles: []string{projectAdminRole}, }, - &project{ + { Name: "project2", Roles: []string{developerRole}, }, diff --git a/src/common/security/local/context_test.go b/src/common/security/local/context_test.go index 95d9b9dd4..0fa389876 100644 --- a/src/common/security/local/context_test.go +++ b/src/common/security/local/context_test.go @@ -19,8 +19,6 @@ import ( "strconv" "testing" - "github.com/stretchr/testify/assert" - "github.com/stretchr/testify/require" "github.com/goharbor/harbor/src/common" "github.com/goharbor/harbor/src/common/dao" "github.com/goharbor/harbor/src/common/dao/project" @@ -28,6 +26,8 @@ import ( "github.com/goharbor/harbor/src/common/utils/log" "github.com/goharbor/harbor/src/ui/promgr" "github.com/goharbor/harbor/src/ui/promgr/pmsdriver/local" + "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/require" ) var ( @@ -283,7 +283,7 @@ func TestHasAllPermWithGroup(t *testing.T) { t.Errorf("Error occurred when GetUser: %v", err) } developer.GroupList = []*models.UserGroup{ - &models.UserGroup{GroupName: "test_group", GroupType: 1, LdapGroupDN: "cn=harbor_user,dc=example,dc=com"}, + {GroupName: "test_group", GroupType: 1, LdapGroupDN: "cn=harbor_user,dc=example,dc=com"}, } ctx := NewSecurityContext(developer, pm) assert.False(t, ctx.HasAllPerm(project.Name)) @@ -360,7 +360,7 @@ func TestSecurityContext_GetRolesByGroup(t *testing.T) { t.Errorf("Error occurred when GetUser: %v", err) } developer.GroupList = []*models.UserGroup{ - &models.UserGroup{GroupName: "test_group", GroupType: 1, LdapGroupDN: "cn=harbor_user,dc=example,dc=com"}, + {GroupName: "test_group", GroupType: 1, LdapGroupDN: "cn=harbor_user,dc=example,dc=com"}, } type fields struct { user *models.User diff --git a/src/common/security/secret/context_test.go b/src/common/security/secret/context_test.go index 4a7bfd501..c7d85eaee 100644 --- a/src/common/security/secret/context_test.go +++ b/src/common/security/secret/context_test.go @@ -17,9 +17,9 @@ package secret import ( "testing" - "github.com/stretchr/testify/assert" "github.com/goharbor/harbor/src/common" "github.com/goharbor/harbor/src/common/secret" + "github.com/stretchr/testify/assert" ) func TestIsAuthenticated(t *testing.T) { diff --git a/src/common/utils/clair/client_test.go b/src/common/utils/clair/client_test.go index 24a04f150..3b7b521f6 100644 --- a/src/common/utils/clair/client_test.go +++ b/src/common/utils/clair/client_test.go @@ -17,9 +17,9 @@ import ( "os" "testing" - "github.com/stretchr/testify/assert" "github.com/goharbor/harbor/src/common/models" "github.com/goharbor/harbor/src/common/utils/clair/test" + "github.com/stretchr/testify/assert" ) var ( diff --git a/src/common/utils/clair/utils_test.go b/src/common/utils/clair/utils_test.go index ebf6eea3a..62c5c2a36 100644 --- a/src/common/utils/clair/utils_test.go +++ b/src/common/utils/clair/utils_test.go @@ -20,8 +20,8 @@ import ( "runtime" "testing" - "github.com/stretchr/testify/assert" "github.com/goharbor/harbor/src/common/models" + "github.com/stretchr/testify/assert" ) func TestParseServerity(t *testing.T) { diff --git a/src/common/utils/ldap/ldap_test.go b/src/common/utils/ldap/ldap_test.go index cf9473349..cbdd7920f 100644 --- a/src/common/utils/ldap/ldap_test.go +++ b/src/common/utils/ldap/ldap_test.go @@ -304,7 +304,7 @@ func TestSession_SearchGroup(t *testing.T) { {"normal search", fields{ldapConfig: ldapConfig}, args{baseDN: "dc=example,dc=com", filter: "objectClass=groupOfNames", groupName: "harbor_users", groupNameAttribute: "cn"}, - []models.LdapGroup{models.LdapGroup{GroupName: "harbor_users", GroupDN: "cn=harbor_users,ou=groups,dc=example,dc=com"}}, false}, + []models.LdapGroup{{GroupName: "harbor_users", GroupDN: "cn=harbor_users,ou=groups,dc=example,dc=com"}}, false}, } for _, tt := range tests { t.Run(tt.name, func(t *testing.T) { @@ -358,7 +358,7 @@ func TestSession_SearchGroupByDN(t *testing.T) { {"normal search", fields{ldapConfig: ldapConfig, ldapGroupConfig: ldapGroupConfig}, args{groupDN: "cn=harbor_users,ou=groups,dc=example,dc=com"}, - []models.LdapGroup{models.LdapGroup{GroupName: "harbor_users", GroupDN: "cn=harbor_users,ou=groups,dc=example,dc=com"}}, false}, + []models.LdapGroup{{GroupName: "harbor_users", GroupDN: "cn=harbor_users,ou=groups,dc=example,dc=com"}}, false}, {"search non-exist group", fields{ldapConfig: ldapConfig, ldapGroupConfig: ldapGroupConfig}, args{groupDN: "cn=harbor_non_users,ou=groups,dc=example,dc=com"}, diff --git a/src/common/utils/notary/helper.go b/src/common/utils/notary/helper.go index 485a6100a..0f8c9912f 100644 --- a/src/common/utils/notary/helper.go +++ b/src/common/utils/notary/helper.go @@ -78,7 +78,7 @@ func GetTargets(notaryEndpoint string, username string, fqRepo string) ([]Target res := []Target{} t, err := tokenutil.MakeToken(username, tokenutil.Notary, []*token.ResourceActions{ - &token.ResourceActions{ + { Type: "repository", Name: fqRepo, Actions: []string{"pull"}, diff --git a/src/common/utils/notary/helper_test.go b/src/common/utils/notary/helper_test.go index ba435b91b..09f631ea7 100644 --- a/src/common/utils/notary/helper_test.go +++ b/src/common/utils/notary/helper_test.go @@ -17,11 +17,11 @@ import ( "encoding/json" "fmt" - "github.com/stretchr/testify/assert" "github.com/goharbor/harbor/src/common" notarytest "github.com/goharbor/harbor/src/common/utils/notary/test" utilstest "github.com/goharbor/harbor/src/common/utils/test" "github.com/goharbor/harbor/src/ui/config" + "github.com/stretchr/testify/assert" "net/http/httptest" "os" diff --git a/src/common/utils/registry/auth/tokenauthorizer_test.go b/src/common/utils/registry/auth/tokenauthorizer_test.go index 6d36f8916..bf6615f81 100644 --- a/src/common/utils/registry/auth/tokenauthorizer_test.go +++ b/src/common/utils/registry/auth/tokenauthorizer_test.go @@ -23,10 +23,10 @@ import ( "time" "github.com/docker/distribution/registry/auth/token" - "github.com/stretchr/testify/assert" - "github.com/stretchr/testify/require" "github.com/goharbor/harbor/src/common/models" "github.com/goharbor/harbor/src/common/utils/test" + "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/require" ) func TestFilterReq(t *testing.T) { diff --git a/src/common/utils/registry/repository_test.go b/src/common/utils/registry/repository_test.go index 615ea00ad..a96d90520 100644 --- a/src/common/utils/registry/repository_test.go +++ b/src/common/utils/registry/repository_test.go @@ -50,7 +50,7 @@ var ( func TestBlobExist(t *testing.T) { handler := func(w http.ResponseWriter, r *http.Request) { path := r.URL.Path - dgt := path[strings.LastIndex(path, "/")+1 : len(path)] + dgt := path[strings.LastIndex(path, "/")+1:] if dgt == digest { w.Header().Add(http.CanonicalHeaderKey("Content-Length"), strconv.Itoa(len(blob))) w.Header().Add(http.CanonicalHeaderKey("Docker-Content-Digest"), digest) @@ -205,7 +205,7 @@ func TestDeleteBlob(t *testing.T) { func TestManifestExist(t *testing.T) { handler := func(w http.ResponseWriter, r *http.Request) { path := r.URL.Path - tg := path[strings.LastIndex(path, "/")+1 : len(path)] + tg := path[strings.LastIndex(path, "/")+1:] if tg == tag { w.Header().Add(http.CanonicalHeaderKey("Docker-Content-Digest"), digest) w.Header().Add(http.CanonicalHeaderKey("Content-Type"), mediaType) diff --git a/src/common/utils/uaa/client_test.go b/src/common/utils/uaa/client_test.go index 487b59e3d..b8b16ec26 100644 --- a/src/common/utils/uaa/client_test.go +++ b/src/common/utils/uaa/client_test.go @@ -2,8 +2,8 @@ package uaa import ( "fmt" - "github.com/stretchr/testify/assert" "github.com/goharbor/harbor/src/common/utils/uaa/test" + "github.com/stretchr/testify/assert" "io/ioutil" "net/http/httptest" "os" diff --git a/src/common/utils/uaa/fake_client.go b/src/common/utils/uaa/fake_client.go index a990b0d27..926e0bd89 100644 --- a/src/common/utils/uaa/fake_client.go +++ b/src/common/utils/uaa/fake_client.go @@ -59,7 +59,7 @@ func (fc *FakeClient) SearchUser(name string) ([]*SearchUserEntry, error) { ExtID: "some-external-id-1", ID: "u-0001", UserName: "one", - Emails: []SearchUserEmailEntry{SearchUserEmailEntry{ + Emails: []SearchUserEmailEntry{{ Primary: false, Value: "one@email.com", }}, @@ -68,7 +68,7 @@ func (fc *FakeClient) SearchUser(name string) ([]*SearchUserEntry, error) { ExtID: "some-external-id-2-a", ID: "u-0002a", UserName: "two", - Emails: []SearchUserEmailEntry{SearchUserEmailEntry{ + Emails: []SearchUserEmailEntry{{ Primary: false, Value: "two@email.com", }}, diff --git a/src/jobservice/api/handler_test.go b/src/jobservice/api/handler_test.go index a50013246..d96d85b14 100644 --- a/src/jobservice/api/handler_test.go +++ b/src/jobservice/api/handler_test.go @@ -424,7 +424,7 @@ func (fc *fakeController) CancelJob(jobID string) error { func (fc *fakeController) CheckStatus() (models.JobPoolStats, error) { return models.JobPoolStats{ - Pools: []*models.JobPoolStatsData{&models.JobPoolStatsData{ + Pools: []*models.JobPoolStatsData{{ WorkerPoolID: "fake_pool_ID", Status: "running", StartedAt: time.Now().Unix(), diff --git a/src/jobservice/api/router.go b/src/jobservice/api/router.go index 762b84d8d..1a56ce184 100644 --- a/src/jobservice/api/router.go +++ b/src/jobservice/api/router.go @@ -6,8 +6,8 @@ import ( "fmt" "net/http" - "github.com/gorilla/mux" "github.com/goharbor/harbor/src/jobservice/errs" + "github.com/gorilla/mux" ) const ( diff --git a/src/jobservice/core/controller.go b/src/jobservice/core/controller.go index bc9b9d5ac..26cbae3cc 100644 --- a/src/jobservice/core/controller.go +++ b/src/jobservice/core/controller.go @@ -7,13 +7,13 @@ import ( "fmt" "io/ioutil" - "github.com/robfig/cron" "github.com/goharbor/harbor/src/jobservice/config" "github.com/goharbor/harbor/src/jobservice/errs" "github.com/goharbor/harbor/src/jobservice/job" "github.com/goharbor/harbor/src/jobservice/models" "github.com/goharbor/harbor/src/jobservice/pool" "github.com/goharbor/harbor/src/jobservice/utils" + "github.com/robfig/cron" ) const ( diff --git a/src/jobservice/core/controller_test.go b/src/jobservice/core/controller_test.go index 2f1d9a1f7..0b7b1adbd 100644 --- a/src/jobservice/core/controller_test.go +++ b/src/jobservice/core/controller_test.go @@ -254,7 +254,7 @@ func (f *fakePool) PeriodicallyEnqueue(jobName string, params models.Parameters, func (f *fakePool) Stats() (models.JobPoolStats, error) { return models.JobPoolStats{ Pools: []*models.JobPoolStatsData{ - &models.JobPoolStatsData{ + { Status: "running", }, }, diff --git a/src/jobservice/job/impl/utils/utils.go b/src/jobservice/job/impl/utils/utils.go index 6d60a2b54..e541c3ac7 100644 --- a/src/jobservice/job/impl/utils/utils.go +++ b/src/jobservice/job/impl/utils/utils.go @@ -68,7 +68,7 @@ func BuildBlobURL(endpoint, repository, digest string) string { func GetTokenForRepo(repository, secret, internalTokenServiceURL string) (string, error) { credential := httpauth.NewSecretAuthorizer(secret) t, err := auth.GetToken(internalTokenServiceURL, true, credential, - []*token.ResourceActions{&token.ResourceActions{ + []*token.ResourceActions{{ Type: "repository", Name: repository, Actions: []string{"pull"}, diff --git a/src/jobservice/opm/op_commands.go b/src/jobservice/opm/op_commands.go index 47e08dd6a..1e90d6d70 100644 --- a/src/jobservice/opm/op_commands.go +++ b/src/jobservice/opm/op_commands.go @@ -10,10 +10,10 @@ import ( "sync" "time" - "github.com/gomodule/redigo/redis" "github.com/goharbor/harbor/src/jobservice/logger" "github.com/goharbor/harbor/src/jobservice/models" "github.com/goharbor/harbor/src/jobservice/utils" + "github.com/gomodule/redigo/redis" ) const ( diff --git a/src/jobservice/opm/redis_job_stats_mgr.go b/src/jobservice/opm/redis_job_stats_mgr.go index f476befdc..4af40bd33 100644 --- a/src/jobservice/opm/redis_job_stats_mgr.go +++ b/src/jobservice/opm/redis_job_stats_mgr.go @@ -16,10 +16,10 @@ import ( "github.com/goharbor/harbor/src/jobservice/errs" "github.com/goharbor/harbor/src/jobservice/logger" - "github.com/gomodule/redigo/redis" "github.com/goharbor/harbor/src/jobservice/job" "github.com/goharbor/harbor/src/jobservice/models" "github.com/goharbor/harbor/src/jobservice/utils" + "github.com/gomodule/redigo/redis" ) const ( diff --git a/src/jobservice/opm/redis_job_stats_mgr_test.go b/src/jobservice/opm/redis_job_stats_mgr_test.go index c54e1c45a..09716551a 100644 --- a/src/jobservice/opm/redis_job_stats_mgr_test.go +++ b/src/jobservice/opm/redis_job_stats_mgr_test.go @@ -12,10 +12,10 @@ import ( "testing" "time" - "github.com/gomodule/redigo/redis" "github.com/goharbor/harbor/src/jobservice/job" "github.com/goharbor/harbor/src/jobservice/models" "github.com/goharbor/harbor/src/jobservice/utils" + "github.com/gomodule/redigo/redis" ) const ( diff --git a/src/jobservice/period/enqueuer.go b/src/jobservice/period/enqueuer.go index 1345b9573..14f1fff6f 100644 --- a/src/jobservice/period/enqueuer.go +++ b/src/jobservice/period/enqueuer.go @@ -7,11 +7,11 @@ import ( "time" "github.com/gocraft/work" - "github.com/gomodule/redigo/redis" - "github.com/robfig/cron" "github.com/goharbor/harbor/src/jobservice/job" "github.com/goharbor/harbor/src/jobservice/logger" "github.com/goharbor/harbor/src/jobservice/utils" + "github.com/gomodule/redigo/redis" + "github.com/robfig/cron" ) const ( diff --git a/src/jobservice/period/redis_scheduler.go b/src/jobservice/period/redis_scheduler.go index 2d1a3abc5..cead8d55c 100644 --- a/src/jobservice/period/redis_scheduler.go +++ b/src/jobservice/period/redis_scheduler.go @@ -13,11 +13,11 @@ import ( "github.com/robfig/cron" - "github.com/gomodule/redigo/redis" "github.com/goharbor/harbor/src/jobservice/env" "github.com/goharbor/harbor/src/jobservice/logger" "github.com/goharbor/harbor/src/jobservice/models" "github.com/goharbor/harbor/src/jobservice/utils" + "github.com/gomodule/redigo/redis" ) const ( diff --git a/src/jobservice/period/sweeper.go b/src/jobservice/period/sweeper.go index 0ffa8c918..21a4371f0 100644 --- a/src/jobservice/period/sweeper.go +++ b/src/jobservice/period/sweeper.go @@ -8,9 +8,9 @@ import ( "github.com/gocraft/work" - "github.com/gomodule/redigo/redis" "github.com/goharbor/harbor/src/jobservice/logger" "github.com/goharbor/harbor/src/jobservice/utils" + "github.com/gomodule/redigo/redis" ) //Sweeper take charge of clearing the outdated data such as scheduled jobs etc.. diff --git a/src/jobservice/pool/message_server.go b/src/jobservice/pool/message_server.go index f360037e3..4a8337031 100644 --- a/src/jobservice/pool/message_server.go +++ b/src/jobservice/pool/message_server.go @@ -14,9 +14,9 @@ import ( "github.com/goharbor/harbor/src/jobservice/opm" "github.com/goharbor/harbor/src/jobservice/period" - "github.com/gomodule/redigo/redis" "github.com/goharbor/harbor/src/jobservice/models" "github.com/goharbor/harbor/src/jobservice/utils" + "github.com/gomodule/redigo/redis" ) const ( diff --git a/src/jobservice/pool/redis_pool.go b/src/jobservice/pool/redis_pool.go index c9b0bb6e9..df737c9bc 100644 --- a/src/jobservice/pool/redis_pool.go +++ b/src/jobservice/pool/redis_pool.go @@ -9,8 +9,6 @@ import ( "time" "github.com/gocraft/work" - "github.com/gomodule/redigo/redis" - "github.com/robfig/cron" "github.com/goharbor/harbor/src/jobservice/env" "github.com/goharbor/harbor/src/jobservice/job" "github.com/goharbor/harbor/src/jobservice/logger" @@ -18,6 +16,8 @@ import ( "github.com/goharbor/harbor/src/jobservice/opm" "github.com/goharbor/harbor/src/jobservice/period" "github.com/goharbor/harbor/src/jobservice/utils" + "github.com/gomodule/redigo/redis" + "github.com/robfig/cron" ) var ( diff --git a/src/jobservice/runtime/bootstrap.go b/src/jobservice/runtime/bootstrap.go index 17778a196..655f87d19 100644 --- a/src/jobservice/runtime/bootstrap.go +++ b/src/jobservice/runtime/bootstrap.go @@ -11,7 +11,6 @@ import ( "syscall" "time" - "github.com/gomodule/redigo/redis" "github.com/goharbor/harbor/src/common/job" "github.com/goharbor/harbor/src/jobservice/api" "github.com/goharbor/harbor/src/jobservice/config" @@ -23,6 +22,7 @@ import ( "github.com/goharbor/harbor/src/jobservice/job/impl/scan" "github.com/goharbor/harbor/src/jobservice/logger" "github.com/goharbor/harbor/src/jobservice/pool" + "github.com/gomodule/redigo/redis" ) const ( diff --git a/src/registryctl/auth/secret_test.go b/src/registryctl/auth/secret_test.go index f2d9da53c..bf96c519b 100644 --- a/src/registryctl/auth/secret_test.go +++ b/src/registryctl/auth/secret_test.go @@ -18,8 +18,8 @@ import ( "net/http" "testing" - "github.com/stretchr/testify/assert" commonsecret "github.com/goharbor/harbor/src/common/secret" + "github.com/stretchr/testify/assert" ) func TestAuthorizeRequestInvalid(t *testing.T) { diff --git a/src/registryctl/client/client_test.go b/src/registryctl/client/client_test.go index 7f9c02b50..397dbbf8c 100644 --- a/src/registryctl/client/client_test.go +++ b/src/registryctl/client/client_test.go @@ -19,8 +19,8 @@ import ( "os" "testing" - "github.com/stretchr/testify/assert" "github.com/goharbor/harbor/src/common/utils/test" + "github.com/stretchr/testify/assert" ) var c Client diff --git a/src/registryctl/handlers/handler.go b/src/registryctl/handlers/handler.go index 89bbb48f2..8365e7a5e 100644 --- a/src/registryctl/handlers/handler.go +++ b/src/registryctl/handlers/handler.go @@ -18,9 +18,9 @@ import ( "net/http" "os" - gorilla_handlers "github.com/gorilla/handlers" "github.com/goharbor/harbor/src/common/utils/log" "github.com/goharbor/harbor/src/registryctl/auth" + gorilla_handlers "github.com/gorilla/handlers" ) // NewHandlerChain returns a gorilla router which is wrapped by authenticate handler diff --git a/src/registryctl/handlers/handler_test.go b/src/registryctl/handlers/handler_test.go index b0693b94a..2225f9f7c 100644 --- a/src/registryctl/handlers/handler_test.go +++ b/src/registryctl/handlers/handler_test.go @@ -20,8 +20,8 @@ import ( "net/http/httptest" "testing" - "github.com/stretchr/testify/assert" "github.com/goharbor/harbor/src/registryctl/auth" + "github.com/stretchr/testify/assert" ) type fakeAuthenticator struct { diff --git a/src/registryctl/handlers/router.go b/src/registryctl/handlers/router.go index e73a7b7e2..a2e7e5a75 100644 --- a/src/registryctl/handlers/router.go +++ b/src/registryctl/handlers/router.go @@ -17,8 +17,8 @@ package handlers import ( "net/http" - "github.com/gorilla/mux" "github.com/goharbor/harbor/src/registryctl/api" + "github.com/gorilla/mux" ) func newRouter() http.Handler { diff --git a/src/replication/core/controller_test.go b/src/replication/core/controller_test.go index d360004cc..eadc1825a 100644 --- a/src/replication/core/controller_test.go +++ b/src/replication/core/controller_test.go @@ -18,13 +18,13 @@ import ( "os" "testing" - "github.com/stretchr/testify/assert" "github.com/goharbor/harbor/src/common/utils/test" "github.com/goharbor/harbor/src/replication" "github.com/goharbor/harbor/src/replication/models" "github.com/goharbor/harbor/src/replication/source" "github.com/goharbor/harbor/src/replication/target" "github.com/goharbor/harbor/src/replication/trigger" + "github.com/stretchr/testify/assert" ) func TestMain(m *testing.M) { @@ -81,7 +81,7 @@ func TestGetCandidates(t *testing.T) { policy := &models.ReplicationPolicy{ ID: 1, Filters: []models.Filter{ - models.Filter{ + { Kind: replication.FilterItemKindTag, Value: "*", }, @@ -94,11 +94,11 @@ func TestGetCandidates(t *testing.T) { sourcer := source.NewSourcer() candidates := []models.FilterItem{ - models.FilterItem{ + { Kind: replication.FilterItemKindTag, Value: "library/hello-world:release-1.0", }, - models.FilterItem{ + { Kind: replication.FilterItemKindTag, Value: "library/hello-world:latest", }, @@ -110,7 +110,7 @@ func TestGetCandidates(t *testing.T) { assert.Equal(t, 2, len(result)) policy.Filters = []models.Filter{ - models.Filter{ + { Kind: replication.FilterItemKindTag, Value: "release-*", }, @@ -121,7 +121,7 @@ func TestGetCandidates(t *testing.T) { // test label filter test.InitDatabaseFromEnv() policy.Filters = []models.Filter{ - models.Filter{ + { Kind: replication.FilterItemKindLabel, Value: int64(1), }, @@ -134,17 +134,17 @@ func TestBuildFilterChain(t *testing.T) { policy := &models.ReplicationPolicy{ ID: 1, Filters: []models.Filter{ - models.Filter{ + { Kind: replication.FilterItemKindRepository, Value: "*", }, - models.Filter{ + { Kind: replication.FilterItemKindTag, Value: "*", }, - models.Filter{ + { Kind: replication.FilterItemKindLabel, Value: int64(1), }, diff --git a/src/replication/event/on_deletion_handler_test.go b/src/replication/event/on_deletion_handler_test.go index b327576e5..e9b100a2a 100644 --- a/src/replication/event/on_deletion_handler_test.go +++ b/src/replication/event/on_deletion_handler_test.go @@ -17,10 +17,10 @@ package event import ( "testing" - "github.com/stretchr/testify/assert" "github.com/goharbor/harbor/src/common/dao" "github.com/goharbor/harbor/src/common/utils/test" "github.com/goharbor/harbor/src/replication/event/notification" + "github.com/stretchr/testify/assert" ) func TestHandleOfOnDeletionHandler(t *testing.T) { diff --git a/src/replication/event/on_push_handler_test.go b/src/replication/event/on_push_handler_test.go index bb94e6b06..15e2bdf7e 100644 --- a/src/replication/event/on_push_handler_test.go +++ b/src/replication/event/on_push_handler_test.go @@ -17,10 +17,10 @@ package event import ( "testing" - "github.com/stretchr/testify/assert" "github.com/goharbor/harbor/src/common/dao" "github.com/goharbor/harbor/src/common/utils/test" "github.com/goharbor/harbor/src/replication/event/notification" + "github.com/stretchr/testify/assert" ) func TestHandleOfOnPushHandler(t *testing.T) { diff --git a/src/replication/event/start_replication_handler_test.go b/src/replication/event/start_replication_handler_test.go index 6a568bda5..70093047d 100644 --- a/src/replication/event/start_replication_handler_test.go +++ b/src/replication/event/start_replication_handler_test.go @@ -17,10 +17,10 @@ package event import ( "testing" - "github.com/stretchr/testify/assert" "github.com/goharbor/harbor/src/common/utils/test" "github.com/goharbor/harbor/src/replication/core" "github.com/goharbor/harbor/src/replication/event/notification" + "github.com/stretchr/testify/assert" ) func TestHandle(t *testing.T) { diff --git a/src/replication/models/filter_test.go b/src/replication/models/filter_test.go index 836ee804d..fa7d7d6db 100644 --- a/src/replication/models/filter_test.go +++ b/src/replication/models/filter_test.go @@ -18,43 +18,43 @@ import ( "testing" "github.com/astaxie/beego/validation" - "github.com/stretchr/testify/assert" "github.com/goharbor/harbor/src/replication" + "github.com/stretchr/testify/assert" ) func TestValid(t *testing.T) { cases := map[*Filter]bool{ - &Filter{}: true, - &Filter{ + {}: true, + { Kind: "invalid_kind", }: true, - &Filter{ + { Kind: replication.FilterItemKindRepository, }: true, - &Filter{ + { Kind: replication.FilterItemKindRepository, Pattern: "*", }: false, - &Filter{ + { Kind: replication.FilterItemKindRepository, Value: "*", }: false, - &Filter{ + { Kind: replication.FilterItemKindLabel, }: true, - &Filter{ + { Kind: replication.FilterItemKindLabel, Value: "", }: true, - &Filter{ + { Kind: replication.FilterItemKindLabel, Value: 1.2, }: true, - &Filter{ + { Kind: replication.FilterItemKindLabel, Value: -1, }: true, - &Filter{ + { Kind: replication.FilterItemKindLabel, Value: 1, }: true, diff --git a/src/replication/models/trigger_test.go b/src/replication/models/trigger_test.go index c9a2a4561..8582a05f2 100644 --- a/src/replication/models/trigger_test.go +++ b/src/replication/models/trigger_test.go @@ -18,20 +18,20 @@ import ( "testing" "github.com/astaxie/beego/validation" - "github.com/stretchr/testify/assert" "github.com/goharbor/harbor/src/replication" + "github.com/stretchr/testify/assert" ) func TestValidOfTrigger(t *testing.T) { cases := map[*Trigger]bool{ - &Trigger{}: true, - &Trigger{ + {}: true, + { Kind: "invalid_kind", }: true, - &Trigger{ + { Kind: replication.TriggerKindImmediate, }: false, - &Trigger{ + { Kind: replication.TriggerKindSchedule, }: true, } @@ -45,24 +45,24 @@ func TestValidOfTrigger(t *testing.T) { func TestValidOfScheduleParam(t *testing.T) { cases := map[*ScheduleParam]bool{ - &ScheduleParam{}: true, - &ScheduleParam{ + {}: true, + { Type: "invalid_type", }: true, - &ScheduleParam{ + { Type: replication.TriggerScheduleDaily, Offtime: 3600*24 + 1, }: true, - &ScheduleParam{ + { Type: replication.TriggerScheduleDaily, Offtime: 3600 * 2, }: false, - &ScheduleParam{ + { Type: replication.TriggerScheduleWeekly, Weekday: 0, Offtime: 3600 * 2, }: true, - &ScheduleParam{ + { Type: replication.TriggerScheduleWeekly, Weekday: 7, Offtime: 3600 * 2, diff --git a/src/replication/policy/manager_test.go b/src/replication/policy/manager_test.go index 55e6e76c1..e6c996d4e 100644 --- a/src/replication/policy/manager_test.go +++ b/src/replication/policy/manager_test.go @@ -18,9 +18,9 @@ import ( "encoding/json" "testing" + "github.com/goharbor/harbor/src/replication/models" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" - "github.com/goharbor/harbor/src/replication/models" ) func TestConvertToPersistModel(t *testing.T) { @@ -31,7 +31,7 @@ func TestConvertToPersistModel(t *testing.T) { Kind: "trigger_kind", } filters := []models.Filter{ - models.Filter{ + { Kind: "filter_kind", Pattern: "filter_pattern", }, diff --git a/src/replication/source/default_filter_chain_test.go b/src/replication/source/default_filter_chain_test.go index 9ff5cb345..0088faeb0 100644 --- a/src/replication/source/default_filter_chain_test.go +++ b/src/replication/source/default_filter_chain_test.go @@ -17,10 +17,10 @@ package source import ( "testing" - "github.com/stretchr/testify/assert" - "github.com/stretchr/testify/require" "github.com/goharbor/harbor/src/replication" "github.com/goharbor/harbor/src/replication/models" + "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/require" ) func TestBuild(t *testing.T) { @@ -41,11 +41,11 @@ func TestDoFilter(t *testing.T) { filters := []Filter{projectFilter, repositoryFilter} items := []models.FilterItem{ - models.FilterItem{ + { Kind: replication.FilterItemKindProject, Value: "library", }, - models.FilterItem{ + { Kind: replication.FilterItemKindProject, Value: "test", }, @@ -53,7 +53,7 @@ func TestDoFilter(t *testing.T) { chain := NewDefaultFilterChain(filters) items = chain.DoFilter(items) assert.EqualValues(t, []models.FilterItem{ - models.FilterItem{ + { Kind: replication.FilterItemKindRepository, Value: "library/ubuntu", }, diff --git a/src/replication/source/label_filter_test.go b/src/replication/source/label_filter_test.go index dc1a7542d..69784d461 100644 --- a/src/replication/source/label_filter_test.go +++ b/src/replication/source/label_filter_test.go @@ -20,8 +20,8 @@ import ( "github.com/goharbor/harbor/src/common/utils/test" "github.com/goharbor/harbor/src/replication" - "github.com/stretchr/testify/assert" "github.com/goharbor/harbor/src/replication/models" + "github.com/stretchr/testify/assert" ) func TestInitOfLabelFilter(t *testing.T) { @@ -38,7 +38,7 @@ func TestDoFilterOfLabelFilter(t *testing.T) { test.InitDatabaseFromEnv() filter := NewLabelFilter(1) items := []models.FilterItem{ - models.FilterItem{ + { Kind: replication.FilterItemKindTag, Value: "library/hello-world:latest", }, diff --git a/src/replication/source/pattern_filter_test.go b/src/replication/source/pattern_filter_test.go index 593620c39..3e01275c8 100644 --- a/src/replication/source/pattern_filter_test.go +++ b/src/replication/source/pattern_filter_test.go @@ -15,9 +15,9 @@ package source import ( - "github.com/stretchr/testify/assert" "github.com/goharbor/harbor/src/replication" "github.com/goharbor/harbor/src/replication/models" + "github.com/stretchr/testify/assert" "testing" ) @@ -34,21 +34,21 @@ func TestPatternFilterGetConvertor(t *testing.T) { func TestPatternFilterDoFilter(t *testing.T) { items := []models.FilterItem{ - models.FilterItem{ + { Kind: replication.FilterItemKindProject, }, - models.FilterItem{ + { Kind: replication.FilterItemKindRepository, }, - models.FilterItem{ + { Kind: replication.FilterItemKindTag, Value: "library/ubuntu:release-14.04", }, - models.FilterItem{ + { Kind: replication.FilterItemKindTag, Value: "library/ubuntu:release-16.04", }, - models.FilterItem{ + { Kind: replication.FilterItemKindTag, Value: "library/ubuntu:test", }, diff --git a/src/replication/source/repository_convertor_test.go b/src/replication/source/repository_convertor_test.go index ee63387ea..65c25689f 100644 --- a/src/replication/source/repository_convertor_test.go +++ b/src/replication/source/repository_convertor_test.go @@ -17,31 +17,31 @@ package source import ( "testing" - "github.com/stretchr/testify/assert" "github.com/goharbor/harbor/src/replication" "github.com/goharbor/harbor/src/replication/models" + "github.com/stretchr/testify/assert" ) func TestRepositoryConvert(t *testing.T) { items := []models.FilterItem{ - models.FilterItem{ + { Kind: replication.FilterItemKindProject, Value: "library", }, - models.FilterItem{ + { Kind: replication.FilterItemKindRepository, }, } expected := []models.FilterItem{ - models.FilterItem{ + { Kind: replication.FilterItemKindRepository, Value: "library/ubuntu", }, - models.FilterItem{ + { Kind: replication.FilterItemKindRepository, Value: "library/centos", }, - models.FilterItem{ + { Kind: replication.FilterItemKindRepository, }, } @@ -66,10 +66,10 @@ func (f *fakeRegistryAdaptor) GetNamespace(name string) models.Namespace { func (f *fakeRegistryAdaptor) GetRepositories(namespace string) []models.Repository { return []models.Repository{ - models.Repository{ + { Name: "library/ubuntu", }, - models.Repository{ + { Name: "library/centos", }, } @@ -81,10 +81,10 @@ func (f *fakeRegistryAdaptor) GetRepository(name string, namespace string) model func (f *fakeRegistryAdaptor) GetTags(repositoryName string, namespace string) []models.Tag { return []models.Tag{ - models.Tag{ + { Name: "14.04", }, - models.Tag{ + { Name: "16.04", }, } diff --git a/src/replication/source/repository_filter_test.go b/src/replication/source/repository_filter_test.go index b2562a736..aecd87a1b 100644 --- a/src/replication/source/repository_filter_test.go +++ b/src/replication/source/repository_filter_test.go @@ -17,10 +17,10 @@ package source import ( "testing" - "github.com/stretchr/testify/assert" "github.com/goharbor/harbor/src/replication" "github.com/goharbor/harbor/src/replication/models" "github.com/goharbor/harbor/src/replication/registry" + "github.com/stretchr/testify/assert" ) func TestInitOfRepositoryFilter(t *testing.T) { @@ -37,7 +37,7 @@ func TestDoFilterOfRepositoryFilter(t *testing.T) { // invalid filter item type filter := NewRepositoryFilter("", ®istry.HarborAdaptor{}) items := filter.DoFilter([]models.FilterItem{ - models.FilterItem{ + { Kind: "invalid_type", }, }) @@ -46,7 +46,7 @@ func TestDoFilterOfRepositoryFilter(t *testing.T) { // empty pattern filter = NewRepositoryFilter("", ®istry.HarborAdaptor{}) items = filter.DoFilter([]models.FilterItem{ - models.FilterItem{ + { Kind: replication.FilterItemKindRepository, Value: "library/hello-world", }, @@ -56,7 +56,7 @@ func TestDoFilterOfRepositoryFilter(t *testing.T) { // non-empty pattern filter = NewRepositoryFilter("*", ®istry.HarborAdaptor{}) items = filter.DoFilter([]models.FilterItem{ - models.FilterItem{ + { Kind: replication.FilterItemKindTag, Value: "library/hello-world", }, @@ -66,7 +66,7 @@ func TestDoFilterOfRepositoryFilter(t *testing.T) { // non-empty pattern filter = NewRepositoryFilter("*", ®istry.HarborAdaptor{}) items = filter.DoFilter([]models.FilterItem{ - models.FilterItem{ + { Kind: replication.FilterItemKindTag, Value: "library/hello-world:latest", }, diff --git a/src/replication/source/tag_combination_filter_test.go b/src/replication/source/tag_combination_filter_test.go index 77ced3256..674509285 100644 --- a/src/replication/source/tag_combination_filter_test.go +++ b/src/replication/source/tag_combination_filter_test.go @@ -15,9 +15,9 @@ package source import ( - "github.com/stretchr/testify/assert" "github.com/goharbor/harbor/src/replication" "github.com/goharbor/harbor/src/replication/models" + "github.com/stretchr/testify/assert" "testing" ) @@ -34,25 +34,25 @@ func TestTagCombinationFilterGetConvertor(t *testing.T) { func TestTagCombinationFilterDoFilter(t *testing.T) { items := []models.FilterItem{ - models.FilterItem{ + { Kind: replication.FilterItemKindProject, }, - models.FilterItem{ + { Kind: replication.FilterItemKindRepository, }, - models.FilterItem{ + { Kind: replication.FilterItemKindTag, Value: "library/ubuntu:invalid_tag:latest", }, - models.FilterItem{ + { Kind: replication.FilterItemKindTag, Value: "library/ubuntu:14.04", }, - models.FilterItem{ + { Kind: replication.FilterItemKindTag, Value: "library/ubuntu:16.04", }, - models.FilterItem{ + { Kind: replication.FilterItemKindTag, Value: "library/centos:7", }, diff --git a/src/replication/source/tag_convertor_test.go b/src/replication/source/tag_convertor_test.go index e23250158..6b212bf92 100644 --- a/src/replication/source/tag_convertor_test.go +++ b/src/replication/source/tag_convertor_test.go @@ -17,31 +17,31 @@ package source import ( "testing" - "github.com/stretchr/testify/assert" "github.com/goharbor/harbor/src/replication" "github.com/goharbor/harbor/src/replication/models" + "github.com/stretchr/testify/assert" ) func TestTagConvert(t *testing.T) { items := []models.FilterItem{ - models.FilterItem{ + { Kind: replication.FilterItemKindRepository, Value: "library/ubuntu", }, - models.FilterItem{ + { Kind: replication.FilterItemKindProject, }, } expected := []models.FilterItem{ - models.FilterItem{ + { Kind: replication.FilterItemKindTag, Value: "library/ubuntu:14.04", }, - models.FilterItem{ + { Kind: replication.FilterItemKindTag, Value: "library/ubuntu:16.04", }, - models.FilterItem{ + { Kind: replication.FilterItemKindProject, }, } diff --git a/src/replication/source/tag_filter_test.go b/src/replication/source/tag_filter_test.go index 31fce28a1..5a70eb2c3 100644 --- a/src/replication/source/tag_filter_test.go +++ b/src/replication/source/tag_filter_test.go @@ -17,10 +17,10 @@ package source import ( "testing" - "github.com/stretchr/testify/assert" "github.com/goharbor/harbor/src/replication" "github.com/goharbor/harbor/src/replication/models" "github.com/goharbor/harbor/src/replication/registry" + "github.com/stretchr/testify/assert" ) func TestInitOfTagFilter(t *testing.T) { @@ -37,7 +37,7 @@ func TestDoFilterOfTagFilter(t *testing.T) { // invalid filter item type filter := NewTagFilter("", ®istry.HarborAdaptor{}) items := filter.DoFilter([]models.FilterItem{ - models.FilterItem{ + { Kind: "invalid_type", }, }) @@ -46,7 +46,7 @@ func TestDoFilterOfTagFilter(t *testing.T) { // empty pattern filter = NewTagFilter("", ®istry.HarborAdaptor{}) items = filter.DoFilter([]models.FilterItem{ - models.FilterItem{ + { Kind: replication.FilterItemKindTag, Value: "library/hello-world:latest", }, @@ -56,7 +56,7 @@ func TestDoFilterOfTagFilter(t *testing.T) { // non-empty pattern filter = NewTagFilter("l*t", ®istry.HarborAdaptor{}) items = filter.DoFilter([]models.FilterItem{ - models.FilterItem{ + { Kind: replication.FilterItemKindTag, Value: "library/hello-world:latest", }, @@ -66,7 +66,7 @@ func TestDoFilterOfTagFilter(t *testing.T) { // non-empty pattern filter = NewTagFilter("lates?", ®istry.HarborAdaptor{}) items = filter.DoFilter([]models.FilterItem{ - models.FilterItem{ + { Kind: replication.FilterItemKindTag, Value: "library/hello-world:latest", }, @@ -76,7 +76,7 @@ func TestDoFilterOfTagFilter(t *testing.T) { // non-empty pattern filter = NewTagFilter("latest?", ®istry.HarborAdaptor{}) items = filter.DoFilter([]models.FilterItem{ - models.FilterItem{ + { Kind: replication.FilterItemKindTag, Value: "library/hello-world:latest", }, diff --git a/src/replication/trigger/immediate_test.go b/src/replication/trigger/immediate_test.go index ef0efa019..4dc6c8849 100644 --- a/src/replication/trigger/immediate_test.go +++ b/src/replication/trigger/immediate_test.go @@ -17,11 +17,11 @@ package trigger import ( "testing" - "github.com/stretchr/testify/assert" - "github.com/stretchr/testify/require" "github.com/goharbor/harbor/src/common/dao" "github.com/goharbor/harbor/src/common/utils/test" "github.com/goharbor/harbor/src/replication" + "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/require" ) func TestKindOfImmediateTrigger(t *testing.T) { diff --git a/src/replication/trigger/manager_test.go b/src/replication/trigger/manager_test.go index 836337e0b..3eabe134b 100644 --- a/src/replication/trigger/manager_test.go +++ b/src/replication/trigger/manager_test.go @@ -17,12 +17,12 @@ package trigger import ( "testing" - "github.com/stretchr/testify/assert" - "github.com/stretchr/testify/require" "github.com/goharbor/harbor/src/common/dao" "github.com/goharbor/harbor/src/common/utils/test" "github.com/goharbor/harbor/src/replication" "github.com/goharbor/harbor/src/replication/models" + "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/require" ) func TestCreateTrigger(t *testing.T) { diff --git a/src/replication/trigger/schedule_test.go b/src/replication/trigger/schedule_test.go index 13402dc91..ddb6095e5 100644 --- a/src/replication/trigger/schedule_test.go +++ b/src/replication/trigger/schedule_test.go @@ -17,8 +17,8 @@ package trigger import ( "testing" - "github.com/stretchr/testify/assert" "github.com/goharbor/harbor/src/replication" + "github.com/stretchr/testify/assert" ) func TestKindOfScheduleTrigger(t *testing.T) { diff --git a/src/replication/trigger/watch_list_test.go b/src/replication/trigger/watch_list_test.go index 298274ec7..7259395f5 100644 --- a/src/replication/trigger/watch_list_test.go +++ b/src/replication/trigger/watch_list_test.go @@ -17,10 +17,10 @@ package trigger import ( "testing" - "github.com/stretchr/testify/assert" - "github.com/stretchr/testify/require" "github.com/goharbor/harbor/src/common/dao" "github.com/goharbor/harbor/src/common/utils/test" + "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/require" ) func TestMethodsOfWatchList(t *testing.T) { diff --git a/src/ui/api/api_test.go b/src/ui/api/api_test.go index 166d7be73..c6411a205 100644 --- a/src/ui/api/api_test.go +++ b/src/ui/api/api_test.go @@ -28,12 +28,12 @@ import ( "github.com/astaxie/beego" "github.com/dghubble/sling" - "github.com/stretchr/testify/assert" - "github.com/stretchr/testify/require" "github.com/goharbor/harbor/src/common/dao" "github.com/goharbor/harbor/src/common/dao/project" common_http "github.com/goharbor/harbor/src/common/http" "github.com/goharbor/harbor/src/common/models" + "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/require" ) var ( diff --git a/src/ui/api/chart_repository_test.go b/src/ui/api/chart_repository_test.go index e53297d81..b64aa1760 100644 --- a/src/ui/api/chart_repository_test.go +++ b/src/ui/api/chart_repository_test.go @@ -228,7 +228,7 @@ func (msc *mockSecurityContext) HasAllPerm(projectIDOrName interface{}) bool { //Get current user's all project func (msc *mockSecurityContext) GetMyProjects() ([]*models.Project, error) { - return []*models.Project{&models.Project{ProjectID: 0, Name: "repo1"}}, nil + return []*models.Project{{ProjectID: 0, Name: "repo1"}}, nil } //Get user's role in provided project diff --git a/src/ui/api/config_test.go b/src/ui/api/config_test.go index 1cdfedde6..7261d661e 100644 --- a/src/ui/api/config_test.go +++ b/src/ui/api/config_test.go @@ -18,9 +18,9 @@ import ( "fmt" "testing" - "github.com/stretchr/testify/assert" "github.com/goharbor/harbor/src/common" "github.com/goharbor/harbor/src/ui/config" + "github.com/stretchr/testify/assert" ) func TestGetConfig(t *testing.T) { diff --git a/src/ui/api/label_test.go b/src/ui/api/label_test.go index 571d99fa4..3e9d675ad 100644 --- a/src/ui/api/label_test.go +++ b/src/ui/api/label_test.go @@ -20,13 +20,13 @@ import ( "net/http/httptest" "testing" - "github.com/stretchr/testify/assert" - "github.com/stretchr/testify/require" "github.com/goharbor/harbor/src/common" "github.com/goharbor/harbor/src/common/dao" "github.com/goharbor/harbor/src/common/models" "github.com/goharbor/harbor/src/replication" rep_models "github.com/goharbor/harbor/src/replication/models" + "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/require" ) var ( @@ -46,7 +46,7 @@ func TestLabelAPIPost(t *testing.T) { cases := []*codeCheckingCase{ // 401 - &codeCheckingCase{ + { request: &testingRequest{ method: http.MethodPost, url: labelAPIBasePath, @@ -55,7 +55,7 @@ func TestLabelAPIPost(t *testing.T) { }, // 400 - &codeCheckingCase{ + { request: &testingRequest{ method: http.MethodPost, url: labelAPIBasePath, @@ -66,7 +66,7 @@ func TestLabelAPIPost(t *testing.T) { }, // 403 non-sysadmin try to create global label - &codeCheckingCase{ + { request: &testingRequest{ method: http.MethodPost, url: labelAPIBasePath, @@ -80,7 +80,7 @@ func TestLabelAPIPost(t *testing.T) { }, // 403 non-member user try to create project label - &codeCheckingCase{ + { request: &testingRequest{ method: http.MethodPost, url: labelAPIBasePath, @@ -95,7 +95,7 @@ func TestLabelAPIPost(t *testing.T) { }, // 403 developer try to create project label - &codeCheckingCase{ + { request: &testingRequest{ method: http.MethodPost, url: labelAPIBasePath, @@ -110,7 +110,7 @@ func TestLabelAPIPost(t *testing.T) { }, // 404 non-exist project - &codeCheckingCase{ + { request: &testingRequest{ method: http.MethodPost, url: labelAPIBasePath, @@ -125,7 +125,7 @@ func TestLabelAPIPost(t *testing.T) { }, // 200 - &codeCheckingCase{ + { request: &testingRequest{ method: http.MethodPost, url: labelAPIBasePath, @@ -141,7 +141,7 @@ func TestLabelAPIPost(t *testing.T) { }, // 409 - &codeCheckingCase{ + { request: &testingRequest{ method: http.MethodPost, url: labelAPIBasePath, @@ -162,7 +162,7 @@ func TestLabelAPIPost(t *testing.T) { func TestLabelAPIGet(t *testing.T) { cases := []*codeCheckingCase{ // 400 - &codeCheckingCase{ + { request: &testingRequest{ method: http.MethodGet, url: fmt.Sprintf("%s/%d", labelAPIBasePath, 0), @@ -171,7 +171,7 @@ func TestLabelAPIGet(t *testing.T) { }, // 404 - &codeCheckingCase{ + { request: &testingRequest{ method: http.MethodGet, url: fmt.Sprintf("%s/%d", labelAPIBasePath, 1000), @@ -180,7 +180,7 @@ func TestLabelAPIGet(t *testing.T) { }, // 200 - &codeCheckingCase{ + { request: &testingRequest{ method: http.MethodGet, url: fmt.Sprintf("%s/%d", labelAPIBasePath, labelID), @@ -194,7 +194,7 @@ func TestLabelAPIGet(t *testing.T) { func TestLabelAPIList(t *testing.T) { cases := []*codeCheckingCase{ // 400 no scope query string - &codeCheckingCase{ + { request: &testingRequest{ method: http.MethodGet, url: labelAPIBasePath, @@ -203,7 +203,7 @@ func TestLabelAPIList(t *testing.T) { }, // 400 invalid scope - &codeCheckingCase{ + { request: &testingRequest{ method: http.MethodGet, url: labelAPIBasePath, @@ -217,7 +217,7 @@ func TestLabelAPIList(t *testing.T) { }, // 400 invalid project_id - &codeCheckingCase{ + { request: &testingRequest{ method: http.MethodGet, url: labelAPIBasePath, @@ -272,7 +272,7 @@ func TestLabelAPIList(t *testing.T) { func TestLabelAPIPut(t *testing.T) { cases := []*codeCheckingCase{ // 401 - &codeCheckingCase{ + { request: &testingRequest{ method: http.MethodPut, url: fmt.Sprintf("%s/%d", labelAPIBasePath, labelID), @@ -281,7 +281,7 @@ func TestLabelAPIPut(t *testing.T) { }, // 400 - &codeCheckingCase{ + { request: &testingRequest{ method: http.MethodPut, url: fmt.Sprintf("%s/%d", labelAPIBasePath, 0), @@ -291,7 +291,7 @@ func TestLabelAPIPut(t *testing.T) { }, // 404 - &codeCheckingCase{ + { request: &testingRequest{ method: http.MethodPut, url: fmt.Sprintf("%s/%d", labelAPIBasePath, 10000), @@ -301,7 +301,7 @@ func TestLabelAPIPut(t *testing.T) { }, // 403 non-member user - &codeCheckingCase{ + { request: &testingRequest{ method: http.MethodPut, url: fmt.Sprintf("%s/%d", labelAPIBasePath, labelID), @@ -311,7 +311,7 @@ func TestLabelAPIPut(t *testing.T) { }, // 403 developer - &codeCheckingCase{ + { request: &testingRequest{ method: http.MethodPut, url: fmt.Sprintf("%s/%d", labelAPIBasePath, labelID), @@ -321,7 +321,7 @@ func TestLabelAPIPut(t *testing.T) { }, // 400 - &codeCheckingCase{ + { request: &testingRequest{ method: http.MethodPut, url: fmt.Sprintf("%s/%d", labelAPIBasePath, labelID), @@ -336,7 +336,7 @@ func TestLabelAPIPut(t *testing.T) { }, // 200 - &codeCheckingCase{ + { request: &testingRequest{ method: http.MethodPut, url: fmt.Sprintf("%s/%d", labelAPIBasePath, labelID), @@ -365,7 +365,7 @@ func TestLabelAPIPut(t *testing.T) { func TestLabelAPIDelete(t *testing.T) { cases := []*codeCheckingCase{ // 401 - &codeCheckingCase{ + { request: &testingRequest{ method: http.MethodDelete, url: fmt.Sprintf("%s/%d", labelAPIBasePath, labelID), @@ -374,7 +374,7 @@ func TestLabelAPIDelete(t *testing.T) { }, // 400 - &codeCheckingCase{ + { request: &testingRequest{ method: http.MethodDelete, url: fmt.Sprintf("%s/%d", labelAPIBasePath, 0), @@ -384,7 +384,7 @@ func TestLabelAPIDelete(t *testing.T) { }, // 404 - &codeCheckingCase{ + { request: &testingRequest{ method: http.MethodDelete, url: fmt.Sprintf("%s/%d", labelAPIBasePath, 10000), @@ -394,7 +394,7 @@ func TestLabelAPIDelete(t *testing.T) { }, // 403 non-member user - &codeCheckingCase{ + { request: &testingRequest{ method: http.MethodDelete, url: fmt.Sprintf("%s/%d", labelAPIBasePath, labelID), @@ -404,7 +404,7 @@ func TestLabelAPIDelete(t *testing.T) { }, // 403 developer - &codeCheckingCase{ + { request: &testingRequest{ method: http.MethodDelete, url: fmt.Sprintf("%s/%d", labelAPIBasePath, labelID), @@ -414,7 +414,7 @@ func TestLabelAPIDelete(t *testing.T) { }, // 200 - &codeCheckingCase{ + { request: &testingRequest{ method: http.MethodDelete, url: fmt.Sprintf("%s/%d", labelAPIBasePath, labelID), @@ -424,7 +424,7 @@ func TestLabelAPIDelete(t *testing.T) { }, // 404 - &codeCheckingCase{ + { request: &testingRequest{ method: http.MethodDelete, url: fmt.Sprintf("%s/%d", labelAPIBasePath, labelID), @@ -477,7 +477,7 @@ func TestListResources(t *testing.T) { cases := []*codeCheckingCase{ // 401 - &codeCheckingCase{ + { request: &testingRequest{ method: http.MethodGet, url: fmt.Sprintf("%s/%d/resources", labelAPIBasePath, globalLabelID), @@ -485,7 +485,7 @@ func TestListResources(t *testing.T) { code: http.StatusUnauthorized, }, // 404 - &codeCheckingCase{ + { request: &testingRequest{ method: http.MethodGet, url: fmt.Sprintf("%s/%d/resources", labelAPIBasePath, 10000), @@ -494,7 +494,7 @@ func TestListResources(t *testing.T) { code: http.StatusNotFound, }, // 403: global level label - &codeCheckingCase{ + { request: &testingRequest{ method: http.MethodGet, url: fmt.Sprintf("%s/%d/resources", labelAPIBasePath, globalLabelID), @@ -503,7 +503,7 @@ func TestListResources(t *testing.T) { code: http.StatusForbidden, }, // 403: project level label - &codeCheckingCase{ + { request: &testingRequest{ method: http.MethodGet, url: fmt.Sprintf("%s/%d/resources", labelAPIBasePath, projectLabelID), diff --git a/src/ui/api/ldap_test.go b/src/ui/api/ldap_test.go index 6f4f943f8..1c5b11674 100644 --- a/src/ui/api/ldap_test.go +++ b/src/ui/api/ldap_test.go @@ -9,14 +9,14 @@ import ( func TestLDAPPing(t *testing.T) { cases := []*codeCheckingCase{ - &codeCheckingCase{ + { request: &testingRequest{ method: http.MethodPost, url: "/api/ldap/ping", }, code: http.StatusUnauthorized, }, - &codeCheckingCase{ + { request: &testingRequest{ method: http.MethodPost, url: "/api/ldap/ping", @@ -24,7 +24,7 @@ func TestLDAPPing(t *testing.T) { }, code: http.StatusOK, }, - &codeCheckingCase{ + { request: &testingRequest{ method: http.MethodPost, url: "/api/ldap/ping", @@ -47,14 +47,14 @@ func TestLDAPPing(t *testing.T) { func TestLDAPUserSearch(t *testing.T) { cases := []*codeCheckingCase{ - &codeCheckingCase{ + { request: &testingRequest{ method: http.MethodGet, url: "/api/ldap/users/search?username=mike", }, code: http.StatusUnauthorized, }, - &codeCheckingCase{ + { request: &testingRequest{ method: http.MethodGet, url: "/api/ldap/users/search?username=mike", @@ -68,14 +68,14 @@ func TestLDAPUserSearch(t *testing.T) { func TestLDAPGroupSearch(t *testing.T) { cases := []*codeCheckingCase{ - &codeCheckingCase{ + { request: &testingRequest{ method: http.MethodGet, url: "/api/ldap/groups/search?groupname=harbor_users", }, code: http.StatusUnauthorized, }, - &codeCheckingCase{ + { request: &testingRequest{ method: http.MethodGet, url: "/api/ldap/groups/search?groupname=harbor_users", @@ -89,14 +89,14 @@ func TestLDAPGroupSearch(t *testing.T) { func TestLDAPGroupSearchWithDN(t *testing.T) { cases := []*codeCheckingCase{ - &codeCheckingCase{ + { request: &testingRequest{ method: http.MethodGet, url: "/api/ldap/groups/search?groupdn=cn=harbor_users,ou=groups,dc=example,dc=com", }, code: http.StatusUnauthorized, }, - &codeCheckingCase{ + { request: &testingRequest{ method: http.MethodGet, url: "/api/ldap/groups/search?groupname=cn=harbor_users,ou=groups,dc=example,dc=com", @@ -110,7 +110,7 @@ func TestLDAPGroupSearchWithDN(t *testing.T) { func TestLDAPImportUser(t *testing.T) { cases := []*codeCheckingCase{ - &codeCheckingCase{ + { request: &testingRequest{ method: http.MethodPost, url: "/api/ldap/users/import", @@ -120,7 +120,7 @@ func TestLDAPImportUser(t *testing.T) { }, code: http.StatusUnauthorized, }, - &codeCheckingCase{ + { request: &testingRequest{ method: http.MethodPost, url: "/api/ldap/users/import", diff --git a/src/ui/api/log_test.go b/src/ui/api/log_test.go index 6e24123f8..75350cdc4 100644 --- a/src/ui/api/log_test.go +++ b/src/ui/api/log_test.go @@ -19,10 +19,10 @@ import ( "testing" "time" - "github.com/stretchr/testify/assert" - "github.com/stretchr/testify/require" "github.com/goharbor/harbor/src/common/dao" "github.com/goharbor/harbor/src/common/models" + "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/require" ) func TestLogGet(t *testing.T) { diff --git a/src/ui/api/metadata_test.go b/src/ui/api/metadata_test.go index 4b19449c1..f55b4b119 100644 --- a/src/ui/api/metadata_test.go +++ b/src/ui/api/metadata_test.go @@ -18,9 +18,9 @@ import ( "net/http" "testing" + "github.com/goharbor/harbor/src/common/models" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" - "github.com/goharbor/harbor/src/common/models" ) func TestValidateProjectMetadata(t *testing.T) { diff --git a/src/ui/api/project_test.go b/src/ui/api/project_test.go index 3a85c7c65..09970fec2 100644 --- a/src/ui/api/project_test.go +++ b/src/ui/api/project_test.go @@ -24,11 +24,11 @@ import ( "github.com/goharbor/harbor/src/chartserver" - "github.com/stretchr/testify/assert" - "github.com/stretchr/testify/require" "github.com/goharbor/harbor/src/common/dao" "github.com/goharbor/harbor/src/common/models" "github.com/goharbor/harbor/tests/apitests/apilib" + "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/require" ) var addProject *apilib.ProjectReq diff --git a/src/ui/api/projectmember_test.go b/src/ui/api/projectmember_test.go index 58fc6cf73..043e5ef9e 100644 --- a/src/ui/api/projectmember_test.go +++ b/src/ui/api/projectmember_test.go @@ -27,7 +27,7 @@ import ( func TestProjectMemberAPI_Get(t *testing.T) { cases := []*codeCheckingCase{ // 401 - &codeCheckingCase{ + { request: &testingRequest{ method: http.MethodGet, url: "/api/projects/1/members", @@ -35,7 +35,7 @@ func TestProjectMemberAPI_Get(t *testing.T) { code: http.StatusUnauthorized, }, //200 - &codeCheckingCase{ + { request: &testingRequest{ method: http.MethodGet, url: "/api/projects/1/members", @@ -44,7 +44,7 @@ func TestProjectMemberAPI_Get(t *testing.T) { code: http.StatusOK, }, //400 - &codeCheckingCase{ + { request: &testingRequest{ method: http.MethodGet, url: "/api/projects/0/members", @@ -53,7 +53,7 @@ func TestProjectMemberAPI_Get(t *testing.T) { code: http.StatusBadRequest, }, // 404 - &codeCheckingCase{ + { request: &testingRequest{ method: http.MethodGet, url: "/api/projects/1/members/121", @@ -62,7 +62,7 @@ func TestProjectMemberAPI_Get(t *testing.T) { code: http.StatusNotFound, }, // 404 - &codeCheckingCase{ + { request: &testingRequest{ method: http.MethodGet, url: "/api/projects/99999/members/121", @@ -87,7 +87,7 @@ func TestProjectMemberAPI_Post(t *testing.T) { cases := []*codeCheckingCase{ // 401 - &codeCheckingCase{ + { request: &testingRequest{ method: http.MethodPost, url: "/api/projects/1/members", @@ -100,7 +100,7 @@ func TestProjectMemberAPI_Post(t *testing.T) { }, code: http.StatusUnauthorized, }, - &codeCheckingCase{ + { request: &testingRequest{ method: http.MethodPost, url: "/api/projects/1/members", @@ -114,7 +114,7 @@ func TestProjectMemberAPI_Post(t *testing.T) { }, code: http.StatusCreated, }, - &codeCheckingCase{ + { request: &testingRequest{ method: http.MethodPost, url: "/api/projects/1/members", @@ -128,7 +128,7 @@ func TestProjectMemberAPI_Post(t *testing.T) { }, code: http.StatusNotFound, }, - &codeCheckingCase{ + { request: &testingRequest{ method: http.MethodPost, url: "/api/projects/1/members", @@ -142,7 +142,7 @@ func TestProjectMemberAPI_Post(t *testing.T) { }, code: http.StatusInternalServerError, }, - &codeCheckingCase{ + { request: &testingRequest{ method: http.MethodGet, url: "/api/projects/1/members?entityname=restuser", @@ -150,7 +150,7 @@ func TestProjectMemberAPI_Post(t *testing.T) { }, code: http.StatusOK, }, - &codeCheckingCase{ + { request: &testingRequest{ method: http.MethodGet, url: "/api/projects/1/members", @@ -187,7 +187,7 @@ func TestProjectMemberAPI_PutAndDelete(t *testing.T) { badURL := fmt.Sprintf("/api/projects/1/members/%v", 0) cases := []*codeCheckingCase{ // 401 - &codeCheckingCase{ + { request: &testingRequest{ method: http.MethodPut, url: URL, @@ -198,7 +198,7 @@ func TestProjectMemberAPI_PutAndDelete(t *testing.T) { code: http.StatusUnauthorized, }, // 200 - &codeCheckingCase{ + { request: &testingRequest{ method: http.MethodPut, url: URL, @@ -210,7 +210,7 @@ func TestProjectMemberAPI_PutAndDelete(t *testing.T) { code: http.StatusOK, }, // 400 - &codeCheckingCase{ + { request: &testingRequest{ method: http.MethodPut, url: badURL, @@ -222,7 +222,7 @@ func TestProjectMemberAPI_PutAndDelete(t *testing.T) { code: http.StatusBadRequest, }, // 400 - &codeCheckingCase{ + { request: &testingRequest{ method: http.MethodPut, url: URL, @@ -234,7 +234,7 @@ func TestProjectMemberAPI_PutAndDelete(t *testing.T) { code: http.StatusBadRequest, }, // 200 - &codeCheckingCase{ + { request: &testingRequest{ method: http.MethodDelete, url: URL, diff --git a/src/ui/api/reg_gc_test.go b/src/ui/api/reg_gc_test.go index 5e064114f..e86737093 100644 --- a/src/ui/api/reg_gc_test.go +++ b/src/ui/api/reg_gc_test.go @@ -3,8 +3,8 @@ package api import ( "testing" - "github.com/stretchr/testify/assert" "github.com/goharbor/harbor/tests/apitests/apilib" + "github.com/stretchr/testify/assert" ) var adminJob001 apilib.GCReq diff --git a/src/ui/api/replication_policy_test.go b/src/ui/api/replication_policy_test.go index d902e4098..acba12a6b 100644 --- a/src/ui/api/replication_policy_test.go +++ b/src/ui/api/replication_policy_test.go @@ -21,14 +21,14 @@ import ( "github.com/goharbor/harbor/src/common/dao/project" - "github.com/stretchr/testify/assert" - "github.com/stretchr/testify/require" "github.com/goharbor/harbor/src/common" "github.com/goharbor/harbor/src/common/dao" "github.com/goharbor/harbor/src/common/models" "github.com/goharbor/harbor/src/replication" rep_models "github.com/goharbor/harbor/src/replication/models" api_models "github.com/goharbor/harbor/src/ui/api/models" + "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/require" ) var ( @@ -63,7 +63,7 @@ func TestRepPolicyAPIPost(t *testing.T) { cases := []*codeCheckingCase{ // 401 - &codeCheckingCase{ + { request: &testingRequest{ method: http.MethodPost, url: repPolicyAPIBasePath, @@ -71,7 +71,7 @@ func TestRepPolicyAPIPost(t *testing.T) { code: http.StatusUnauthorized, }, // 403 - &codeCheckingCase{ + { request: &testingRequest{ method: http.MethodPost, url: repPolicyAPIBasePath, @@ -81,7 +81,7 @@ func TestRepPolicyAPIPost(t *testing.T) { }, // 400, invalid name - &codeCheckingCase{ + { request: &testingRequest{ method: http.MethodPost, url: repPolicyAPIBasePath, @@ -91,7 +91,7 @@ func TestRepPolicyAPIPost(t *testing.T) { code: http.StatusBadRequest, }, // 400, invalid projects - &codeCheckingCase{ + { request: &testingRequest{ method: http.MethodPost, url: repPolicyAPIBasePath, @@ -103,14 +103,14 @@ func TestRepPolicyAPIPost(t *testing.T) { code: http.StatusBadRequest, }, // 400, invalid targets - &codeCheckingCase{ + { request: &testingRequest{ method: http.MethodPost, url: repPolicyAPIBasePath, bodyJSON: &api_models.ReplicationPolicy{ Name: policyName, Projects: []*models.Project{ - &models.Project{ + { ProjectID: projectID, }, }, @@ -120,24 +120,24 @@ func TestRepPolicyAPIPost(t *testing.T) { code: http.StatusBadRequest, }, // 400, invalid filters - &codeCheckingCase{ + { request: &testingRequest{ method: http.MethodPost, url: repPolicyAPIBasePath, bodyJSON: &api_models.ReplicationPolicy{ Name: policyName, Projects: []*models.Project{ - &models.Project{ + { ProjectID: projectID, }, }, Targets: []*models.RepTarget{ - &models.RepTarget{ + { ID: targetID, }, }, Filters: []rep_models.Filter{ - rep_models.Filter{ + { Kind: "invalid_filter_kind", Pattern: "", }, @@ -148,24 +148,24 @@ func TestRepPolicyAPIPost(t *testing.T) { code: http.StatusBadRequest, }, // 400, invalid trigger - &codeCheckingCase{ + { request: &testingRequest{ method: http.MethodPost, url: repPolicyAPIBasePath, bodyJSON: &api_models.ReplicationPolicy{ Name: policyName, Projects: []*models.Project{ - &models.Project{ + { ProjectID: projectID, }, }, Targets: []*models.RepTarget{ - &models.RepTarget{ + { ID: targetID, }, }, Filters: []rep_models.Filter{ - rep_models.Filter{ + { Kind: replication.FilterItemKindRepository, Pattern: "*", }, @@ -179,24 +179,24 @@ func TestRepPolicyAPIPost(t *testing.T) { code: http.StatusBadRequest, }, // 404, project not found - &codeCheckingCase{ + { request: &testingRequest{ method: http.MethodPost, url: repPolicyAPIBasePath, bodyJSON: &api_models.ReplicationPolicy{ Name: policyName, Projects: []*models.Project{ - &models.Project{ + { ProjectID: 10000, }, }, Targets: []*models.RepTarget{ - &models.RepTarget{ + { ID: targetID, }, }, Filters: []rep_models.Filter{ - rep_models.Filter{ + { Kind: replication.FilterItemKindRepository, Pattern: "*", }, @@ -210,24 +210,24 @@ func TestRepPolicyAPIPost(t *testing.T) { code: http.StatusNotFound, }, // 404, target not found - &codeCheckingCase{ + { request: &testingRequest{ method: http.MethodPost, url: repPolicyAPIBasePath, bodyJSON: &api_models.ReplicationPolicy{ Name: policyName, Projects: []*models.Project{ - &models.Project{ + { ProjectID: projectID, }, }, Targets: []*models.RepTarget{ - &models.RepTarget{ + { ID: 10000, }, }, Filters: []rep_models.Filter{ - rep_models.Filter{ + { Kind: replication.FilterItemKindRepository, Pattern: "*", }, @@ -241,28 +241,28 @@ func TestRepPolicyAPIPost(t *testing.T) { code: http.StatusNotFound, }, // 404, label not found - &codeCheckingCase{ + { request: &testingRequest{ method: http.MethodPost, url: repPolicyAPIBasePath, bodyJSON: &api_models.ReplicationPolicy{ Name: policyName, Projects: []*models.Project{ - &models.Project{ + { ProjectID: projectID, }, }, Targets: []*models.RepTarget{ - &models.RepTarget{ + { ID: targetID, }, }, Filters: []rep_models.Filter{ - rep_models.Filter{ + { Kind: replication.FilterItemKindRepository, Pattern: "*", }, - rep_models.Filter{ + { Kind: replication.FilterItemKindLabel, Value: 10000, }, @@ -276,28 +276,28 @@ func TestRepPolicyAPIPost(t *testing.T) { code: http.StatusNotFound, }, // 201 - &codeCheckingCase{ + { request: &testingRequest{ method: http.MethodPost, url: repPolicyAPIBasePath, bodyJSON: &api_models.ReplicationPolicy{ Name: policyName, Projects: []*models.Project{ - &models.Project{ + { ProjectID: projectID, }, }, Targets: []*models.RepTarget{ - &models.RepTarget{ + { ID: targetID, }, }, Filters: []rep_models.Filter{ - rep_models.Filter{ + { Kind: replication.FilterItemKindRepository, Pattern: "*", }, - rep_models.Filter{ + { Kind: replication.FilterItemKindLabel, Value: labelID2, }, @@ -320,7 +320,7 @@ func TestRepPolicyAPIGet(t *testing.T) { cases := []*codeCheckingCase{ // 404 - &codeCheckingCase{ + { request: &testingRequest{ method: http.MethodGet, url: fmt.Sprintf("%s/%d", repPolicyAPIBasePath, 10000), @@ -329,7 +329,7 @@ func TestRepPolicyAPIGet(t *testing.T) { code: http.StatusNotFound, }, // 401 - &codeCheckingCase{ + { request: &testingRequest{ method: http.MethodGet, url: fmt.Sprintf("%s/%d", repPolicyAPIBasePath, policyID), @@ -512,7 +512,7 @@ func TestRepPolicyAPIList(t *testing.T) { func TestRepPolicyAPIPut(t *testing.T) { cases := []*codeCheckingCase{ // 404 - &codeCheckingCase{ + { request: &testingRequest{ method: http.MethodPut, url: fmt.Sprintf("%s/%d", repPolicyAPIBasePath, 10000), @@ -521,24 +521,24 @@ func TestRepPolicyAPIPut(t *testing.T) { code: http.StatusNotFound, }, // 400, invalid trigger - &codeCheckingCase{ + { request: &testingRequest{ method: http.MethodPut, url: fmt.Sprintf("%s/%d", repPolicyAPIBasePath, policyID), bodyJSON: &api_models.ReplicationPolicy{ Name: policyName, Projects: []*models.Project{ - &models.Project{ + { ProjectID: projectID, }, }, Targets: []*models.RepTarget{ - &models.RepTarget{ + { ID: targetID, }, }, Filters: []rep_models.Filter{ - rep_models.Filter{ + { Kind: replication.FilterItemKindRepository, Pattern: "*", }, @@ -552,24 +552,24 @@ func TestRepPolicyAPIPut(t *testing.T) { code: http.StatusBadRequest, }, // 200 - &codeCheckingCase{ + { request: &testingRequest{ method: http.MethodPut, url: fmt.Sprintf("%s/%d", repPolicyAPIBasePath, policyID), bodyJSON: &api_models.ReplicationPolicy{ Name: policyName, Projects: []*models.Project{ - &models.Project{ + { ProjectID: projectID, }, }, Targets: []*models.RepTarget{ - &models.RepTarget{ + { ID: targetID, }, }, Filters: []rep_models.Filter{ - rep_models.Filter{ + { Kind: replication.FilterItemKindRepository, Pattern: "*", }, @@ -590,7 +590,7 @@ func TestRepPolicyAPIPut(t *testing.T) { func TestRepPolicyAPIDelete(t *testing.T) { cases := []*codeCheckingCase{ // 404 - &codeCheckingCase{ + { request: &testingRequest{ method: http.MethodDelete, url: fmt.Sprintf("%s/%d", repPolicyAPIBasePath, 10000), @@ -599,7 +599,7 @@ func TestRepPolicyAPIDelete(t *testing.T) { code: http.StatusNotFound, }, // 200 - &codeCheckingCase{ + { request: &testingRequest{ method: http.MethodDelete, url: fmt.Sprintf("%s/%d", repPolicyAPIBasePath, policyID), @@ -627,7 +627,7 @@ func TestConvertToRepPolicy(t *testing.T) { Name: "policy", Description: "description", Filters: []rep_models.Filter{ - rep_models.Filter{ + { Kind: "filter_kind_01", Pattern: "*", }, @@ -637,13 +637,13 @@ func TestConvertToRepPolicy(t *testing.T) { Kind: "trigger_kind_01", }, Projects: []*models.Project{ - &models.Project{ + { ProjectID: 1, Name: "library", }, }, Targets: []*models.RepTarget{ - &models.RepTarget{ + { ID: 1, }, }, @@ -653,7 +653,7 @@ func TestConvertToRepPolicy(t *testing.T) { Name: "policy", Description: "description", Filters: []rep_models.Filter{ - rep_models.Filter{ + { Kind: "filter_kind_01", Pattern: "*", }, diff --git a/src/ui/api/replication_test.go b/src/ui/api/replication_test.go index 97447d61f..991463360 100644 --- a/src/ui/api/replication_test.go +++ b/src/ui/api/replication_test.go @@ -18,11 +18,11 @@ import ( "net/http" "testing" - "github.com/stretchr/testify/require" "github.com/goharbor/harbor/src/common/dao" "github.com/goharbor/harbor/src/common/models" "github.com/goharbor/harbor/src/replication" api_models "github.com/goharbor/harbor/src/ui/api/models" + "github.com/stretchr/testify/require" ) const ( @@ -52,7 +52,7 @@ func TestReplicationAPIPost(t *testing.T) { cases := []*codeCheckingCase{ // 401 - &codeCheckingCase{ + { request: &testingRequest{ method: http.MethodPost, url: replicationAPIBaseURL, @@ -63,7 +63,7 @@ func TestReplicationAPIPost(t *testing.T) { code: http.StatusUnauthorized, }, // 404 - &codeCheckingCase{ + { request: &testingRequest{ method: http.MethodPost, url: replicationAPIBaseURL, @@ -75,7 +75,7 @@ func TestReplicationAPIPost(t *testing.T) { code: http.StatusNotFound, }, // 200 - &codeCheckingCase{ + { request: &testingRequest{ method: http.MethodPost, url: replicationAPIBaseURL, diff --git a/src/ui/api/repository_label_test.go b/src/ui/api/repository_label_test.go index 2a89dfd34..18bab78be 100644 --- a/src/ui/api/repository_label_test.go +++ b/src/ui/api/repository_label_test.go @@ -19,11 +19,11 @@ import ( "net/http" "testing" - "github.com/stretchr/testify/assert" - "github.com/stretchr/testify/require" "github.com/goharbor/harbor/src/common" "github.com/goharbor/harbor/src/common/dao" "github.com/goharbor/harbor/src/common/models" + "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/require" ) var ( @@ -60,7 +60,7 @@ func TestAddToImage(t *testing.T) { cases := []*codeCheckingCase{ // 401 - &codeCheckingCase{ + { request: &testingRequest{ url: fmt.Sprintf("%s/%s/tags/%s/labels", resourceLabelAPIBasePath, repository, tag), @@ -69,7 +69,7 @@ func TestAddToImage(t *testing.T) { code: http.StatusUnauthorized, }, // 403 - &codeCheckingCase{ + { request: &testingRequest{ url: fmt.Sprintf("%s/%s/tags/%s/labels", resourceLabelAPIBasePath, repository, tag), @@ -79,7 +79,7 @@ func TestAddToImage(t *testing.T) { code: http.StatusForbidden, }, // 404 repository doesn't exist - &codeCheckingCase{ + { request: &testingRequest{ url: fmt.Sprintf("%s/library/non-exist-repo/tags/%s/labels", resourceLabelAPIBasePath, tag), method: http.MethodPost, @@ -88,7 +88,7 @@ func TestAddToImage(t *testing.T) { code: http.StatusNotFound, }, // 404 image doesn't exist - &codeCheckingCase{ + { request: &testingRequest{ url: fmt.Sprintf("%s/%s/tags/non-exist-tag/labels", resourceLabelAPIBasePath, repository), method: http.MethodPost, @@ -97,7 +97,7 @@ func TestAddToImage(t *testing.T) { code: http.StatusNotFound, }, // 400 - &codeCheckingCase{ + { request: &testingRequest{ url: fmt.Sprintf("%s/%s/tags/%s/labels", resourceLabelAPIBasePath, repository, tag), method: http.MethodPost, @@ -106,7 +106,7 @@ func TestAddToImage(t *testing.T) { code: http.StatusBadRequest, }, // 404 label doesn't exist - &codeCheckingCase{ + { request: &testingRequest{ url: fmt.Sprintf("%s/%s/tags/%s/labels", resourceLabelAPIBasePath, repository, tag), @@ -121,7 +121,7 @@ func TestAddToImage(t *testing.T) { code: http.StatusNotFound, }, // 400 system level label - &codeCheckingCase{ + { request: &testingRequest{ url: fmt.Sprintf("%s/%s/tags/%s/labels", resourceLabelAPIBasePath, repository, tag), @@ -136,7 +136,7 @@ func TestAddToImage(t *testing.T) { code: http.StatusBadRequest, }, // 400 try to add the label of project1 to the image under project2 - &codeCheckingCase{ + { request: &testingRequest{ url: fmt.Sprintf("%s/%s/tags/%s/labels", resourceLabelAPIBasePath, repository, tag), @@ -151,7 +151,7 @@ func TestAddToImage(t *testing.T) { code: http.StatusBadRequest, }, // 200 - &codeCheckingCase{ + { request: &testingRequest{ url: fmt.Sprintf("%s/%s/tags/%s/labels", resourceLabelAPIBasePath, repository, tag), diff --git a/src/ui/api/repository_test.go b/src/ui/api/repository_test.go index 068586f55..20307284f 100644 --- a/src/ui/api/repository_test.go +++ b/src/ui/api/repository_test.go @@ -18,11 +18,11 @@ import ( "net/http" "testing" - "github.com/stretchr/testify/assert" - "github.com/stretchr/testify/require" "github.com/goharbor/harbor/src/common/dao" "github.com/goharbor/harbor/src/common/dao/project" "github.com/goharbor/harbor/src/common/models" + "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/require" ) func TestGetRepos(t *testing.T) { @@ -256,7 +256,7 @@ func TestPutOfRepository(t *testing.T) { cases := []*codeCheckingCase{ // 404 - &codeCheckingCase{ + { request: &testingRequest{ method: http.MethodPut, url: base + "non_exist_repository", @@ -265,7 +265,7 @@ func TestPutOfRepository(t *testing.T) { code: http.StatusNotFound, }, // 401 - &codeCheckingCase{ + { request: &testingRequest{ method: http.MethodPut, url: base + "library/hello-world", @@ -274,7 +274,7 @@ func TestPutOfRepository(t *testing.T) { code: http.StatusUnauthorized, }, // 403 non-member - &codeCheckingCase{ + { request: &testingRequest{ method: http.MethodPut, url: base + "library/hello-world", @@ -284,7 +284,7 @@ func TestPutOfRepository(t *testing.T) { code: http.StatusForbidden, }, // 403 project guest - &codeCheckingCase{ + { request: &testingRequest{ method: http.MethodPut, url: base + "library/hello-world", @@ -294,7 +294,7 @@ func TestPutOfRepository(t *testing.T) { code: http.StatusForbidden, }, // 200 project developer - &codeCheckingCase{ + { request: &testingRequest{ method: http.MethodPut, url: base + "library/hello-world", @@ -304,7 +304,7 @@ func TestPutOfRepository(t *testing.T) { code: http.StatusOK, }, // 200 project admin - &codeCheckingCase{ + { request: &testingRequest{ method: http.MethodPut, url: base + "library/hello-world", @@ -314,7 +314,7 @@ func TestPutOfRepository(t *testing.T) { code: http.StatusOK, }, // 200 system admin - &codeCheckingCase{ + { request: &testingRequest{ method: http.MethodPut, url: base + "library/hello-world", diff --git a/src/ui/api/search_test.go b/src/ui/api/search_test.go index 4a20f3ba6..a3e9535c6 100644 --- a/src/ui/api/search_test.go +++ b/src/ui/api/search_test.go @@ -21,10 +21,10 @@ import ( "github.com/goharbor/harbor/src/common" "github.com/goharbor/harbor/src/common/models" - "github.com/stretchr/testify/assert" - "github.com/stretchr/testify/require" "github.com/goharbor/harbor/src/common/dao" member "github.com/goharbor/harbor/src/common/dao/project" + "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/require" ) func TestSearch(t *testing.T) { diff --git a/src/ui/api/target_test.go b/src/ui/api/target_test.go index 8c505ad55..f79479dac 100644 --- a/src/ui/api/target_test.go +++ b/src/ui/api/target_test.go @@ -20,9 +20,9 @@ import ( "strconv" "testing" + "github.com/goharbor/harbor/tests/apitests/apilib" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" - "github.com/goharbor/harbor/tests/apitests/apilib" ) const ( diff --git a/src/ui/api/user_test.go b/src/ui/api/user_test.go index da00001b3..275c5c875 100644 --- a/src/ui/api/user_test.go +++ b/src/ui/api/user_test.go @@ -18,13 +18,13 @@ import ( "net/http" "testing" - "github.com/stretchr/testify/require" "github.com/goharbor/harbor/src/common/dao" + "github.com/stretchr/testify/require" - "github.com/stretchr/testify/assert" "github.com/goharbor/harbor/src/common/api" "github.com/goharbor/harbor/src/common/models" "github.com/goharbor/harbor/tests/apitests/apilib" + "github.com/stretchr/testify/assert" "github.com/astaxie/beego" ) @@ -360,7 +360,7 @@ func TestUsersUpdatePassword(t *testing.T) { cases := []*codeCheckingCase{ // unauthorized - &codeCheckingCase{ + { request: &testingRequest{ method: http.MethodPut, url: buildChangeUserPasswordURL(user01.UserID), @@ -368,7 +368,7 @@ func TestUsersUpdatePassword(t *testing.T) { code: http.StatusUnauthorized, }, // 404 - &codeCheckingCase{ + { request: &testingRequest{ method: http.MethodPut, url: buildChangeUserPasswordURL(10000), @@ -380,7 +380,7 @@ func TestUsersUpdatePassword(t *testing.T) { code: http.StatusNotFound, }, // 403, a normal user tries to change password of others - &codeCheckingCase{ + { request: &testingRequest{ method: http.MethodPut, url: buildChangeUserPasswordURL(user02.UserID), @@ -392,7 +392,7 @@ func TestUsersUpdatePassword(t *testing.T) { code: http.StatusForbidden, }, // 400, empty old password - &codeCheckingCase{ + { request: &testingRequest{ method: http.MethodPut, url: buildChangeUserPasswordURL(user01.UserID), @@ -405,7 +405,7 @@ func TestUsersUpdatePassword(t *testing.T) { code: http.StatusBadRequest, }, // 400, empty new password - &codeCheckingCase{ + { request: &testingRequest{ method: http.MethodPut, url: buildChangeUserPasswordURL(user01.UserID), @@ -420,7 +420,7 @@ func TestUsersUpdatePassword(t *testing.T) { code: http.StatusBadRequest, }, // 403, incorrect old password - &codeCheckingCase{ + { request: &testingRequest{ method: http.MethodPut, url: buildChangeUserPasswordURL(user01.UserID), @@ -436,7 +436,7 @@ func TestUsersUpdatePassword(t *testing.T) { code: http.StatusForbidden, }, // 200, normal user change own password - &codeCheckingCase{ + { request: &testingRequest{ method: http.MethodPut, url: buildChangeUserPasswordURL(user01.UserID), @@ -453,7 +453,7 @@ func TestUsersUpdatePassword(t *testing.T) { }, // 400, admin user change password of others. // the new password is same with the old one - &codeCheckingCase{ + { request: &testingRequest{ method: http.MethodPut, url: buildChangeUserPasswordURL(user01.UserID), @@ -465,7 +465,7 @@ func TestUsersUpdatePassword(t *testing.T) { code: http.StatusBadRequest, }, // 200, admin user change password of others - &codeCheckingCase{ + { request: &testingRequest{ method: http.MethodPut, url: buildChangeUserPasswordURL(user01.UserID), diff --git a/src/ui/api/usergroup_test.go b/src/ui/api/usergroup_test.go index aa5b3aa99..5390d5368 100644 --- a/src/ui/api/usergroup_test.go +++ b/src/ui/api/usergroup_test.go @@ -44,7 +44,7 @@ func TestUserGroupAPI_GetAndDelete(t *testing.T) { defer group.DeleteUserGroup(groupID) cases := []*codeCheckingCase{ // 401 - &codeCheckingCase{ + { request: &testingRequest{ method: http.MethodGet, url: URL, @@ -53,7 +53,7 @@ func TestUserGroupAPI_GetAndDelete(t *testing.T) { }, // 200 - &codeCheckingCase{ + { request: &testingRequest{ method: http.MethodGet, url: fmt.Sprintf("/api/usergroups/%d", groupID), @@ -62,7 +62,7 @@ func TestUserGroupAPI_GetAndDelete(t *testing.T) { code: http.StatusOK, }, // 200 - &codeCheckingCase{ + { request: &testingRequest{ method: http.MethodGet, url: fmt.Sprintf("/api/usergroups"), @@ -71,7 +71,7 @@ func TestUserGroupAPI_GetAndDelete(t *testing.T) { code: http.StatusOK, }, // 200 - &codeCheckingCase{ + { request: &testingRequest{ method: http.MethodDelete, url: fmt.Sprintf("/api/usergroups/%d", groupID), @@ -97,7 +97,7 @@ func TestUserGroupAPI_Post(t *testing.T) { cases := []*codeCheckingCase{ //409 - &codeCheckingCase{ + { request: &testingRequest{ method: http.MethodPost, url: "/api/usergroups", @@ -127,7 +127,7 @@ func TestUserGroupAPI_Put(t *testing.T) { } cases := []*codeCheckingCase{ //401 - &codeCheckingCase{ + { request: &testingRequest{ method: http.MethodPut, url: fmt.Sprintf("/api/usergroups/%d", groupID), @@ -138,7 +138,7 @@ func TestUserGroupAPI_Put(t *testing.T) { code: http.StatusUnauthorized, }, //200 - &codeCheckingCase{ + { request: &testingRequest{ method: http.MethodPut, url: fmt.Sprintf("/api/usergroups/%d", groupID), diff --git a/src/ui/auth/auth_test.go b/src/ui/auth/auth_test.go index e1273d48b..5b7b2fee0 100644 --- a/src/ui/auth/auth_test.go +++ b/src/ui/auth/auth_test.go @@ -17,9 +17,9 @@ import ( "testing" "time" - "github.com/stretchr/testify/assert" "github.com/goharbor/harbor/src/common" "github.com/goharbor/harbor/src/common/models" + "github.com/stretchr/testify/assert" ) var l = NewUserLock(2 * time.Second) diff --git a/src/ui/auth/uaa/uaa_test.go b/src/ui/auth/uaa/uaa_test.go index 65601df3f..1037e0d2b 100644 --- a/src/ui/auth/uaa/uaa_test.go +++ b/src/ui/auth/uaa/uaa_test.go @@ -18,13 +18,13 @@ import ( "os" "testing" - "github.com/stretchr/testify/assert" "github.com/goharbor/harbor/src/common/dao" "github.com/goharbor/harbor/src/common/models" "github.com/goharbor/harbor/src/common/utils/test" utilstest "github.com/goharbor/harbor/src/common/utils/test" "github.com/goharbor/harbor/src/common/utils/uaa" "github.com/goharbor/harbor/src/ui/config" + "github.com/stretchr/testify/assert" ) func TestMain(m *testing.M) { diff --git a/src/ui/config/config_test.go b/src/ui/config/config_test.go index 495aeb499..42bc16cbf 100644 --- a/src/ui/config/config_test.go +++ b/src/ui/config/config_test.go @@ -19,9 +19,9 @@ import ( "runtime" "testing" - "github.com/stretchr/testify/assert" "github.com/goharbor/harbor/src/common" "github.com/goharbor/harbor/src/common/utils/test" + "github.com/stretchr/testify/assert" ) // test functions under package ui/config diff --git a/src/ui/controllers/controllers_test.go b/src/ui/controllers/controllers_test.go index c8079853a..733d34129 100644 --- a/src/ui/controllers/controllers_test.go +++ b/src/ui/controllers/controllers_test.go @@ -26,13 +26,13 @@ import ( "strings" "github.com/astaxie/beego" - "github.com/stretchr/testify/assert" "github.com/goharbor/harbor/src/common" "github.com/goharbor/harbor/src/common/dao" "github.com/goharbor/harbor/src/common/models" "github.com/goharbor/harbor/src/common/utils/test" "github.com/goharbor/harbor/src/ui/config" "github.com/goharbor/harbor/src/ui/proxy" + "github.com/stretchr/testify/assert" ) //const ( diff --git a/src/ui/filter/readonly_test.go b/src/ui/filter/readonly_test.go index 856a4afe4..0008a42d0 100644 --- a/src/ui/filter/readonly_test.go +++ b/src/ui/filter/readonly_test.go @@ -20,10 +20,10 @@ import ( "os" "testing" - "github.com/stretchr/testify/assert" "github.com/goharbor/harbor/src/common" utilstest "github.com/goharbor/harbor/src/common/utils/test" "github.com/goharbor/harbor/src/ui/config" + "github.com/stretchr/testify/assert" ) func TestReadonlyFilter(t *testing.T) { diff --git a/src/ui/filter/security.go b/src/ui/filter/security.go index 83780c9ba..8afe0c75a 100644 --- a/src/ui/filter/security.go +++ b/src/ui/filter/security.go @@ -58,22 +58,22 @@ var ( // in the slice basicAuthReqPatterns = []*pathMethod{ // create project - &pathMethod{ + { path: "/api/projects", method: http.MethodPost, }, // token service - &pathMethod{ + { path: "/service/token", method: http.MethodGet, }, // delete repository - &pathMethod{ + { path: "/api/repositories/" + reference.NameRegexp.String(), method: http.MethodDelete, }, // delete tag - &pathMethod{ + { path: "/api/repositories/" + reference.NameRegexp.String() + "/tags/" + reference.TagRegexp.String(), method: http.MethodDelete, }, diff --git a/src/ui/filter/security_test.go b/src/ui/filter/security_test.go index 4c9110409..4df447500 100644 --- a/src/ui/filter/security_test.go +++ b/src/ui/filter/security_test.go @@ -28,7 +28,6 @@ import ( "github.com/astaxie/beego" beegoctx "github.com/astaxie/beego/context" "github.com/astaxie/beego/session" - "github.com/stretchr/testify/assert" "github.com/goharbor/harbor/src/common/dao" "github.com/goharbor/harbor/src/common/models" commonsecret "github.com/goharbor/harbor/src/common/secret" @@ -40,6 +39,7 @@ import ( "github.com/goharbor/harbor/src/ui/config" "github.com/goharbor/harbor/src/ui/promgr" driver_local "github.com/goharbor/harbor/src/ui/promgr/pmsdriver/local" + "github.com/stretchr/testify/assert" ) func TestMain(m *testing.M) { diff --git a/src/ui/promgr/metamgr/metamgr_test.go b/src/ui/promgr/metamgr/metamgr_test.go index 32f1fa823..632265de4 100644 --- a/src/ui/promgr/metamgr/metamgr_test.go +++ b/src/ui/promgr/metamgr/metamgr_test.go @@ -18,10 +18,10 @@ import ( "os" "testing" - "github.com/stretchr/testify/assert" - "github.com/stretchr/testify/require" "github.com/goharbor/harbor/src/common/dao" "github.com/goharbor/harbor/src/common/utils/test" + "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/require" ) var mgr = NewDefaultProjectMetadataManager() diff --git a/src/ui/promgr/pmsdriver/admiral/admiral_test.go b/src/ui/promgr/pmsdriver/admiral/admiral_test.go index c4aadfc14..88c3751e1 100644 --- a/src/ui/promgr/pmsdriver/admiral/admiral_test.go +++ b/src/ui/promgr/pmsdriver/admiral/admiral_test.go @@ -19,10 +19,10 @@ import ( "sort" "testing" - "github.com/stretchr/testify/assert" - "github.com/stretchr/testify/require" "github.com/goharbor/harbor/src/common/models" errutil "github.com/goharbor/harbor/src/common/utils/error" + "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/require" ) var ( diff --git a/src/ui/promgr/pmsdriver/local/local_test.go b/src/ui/promgr/pmsdriver/local/local_test.go index b30b48ed3..a5cb98c15 100644 --- a/src/ui/promgr/pmsdriver/local/local_test.go +++ b/src/ui/promgr/pmsdriver/local/local_test.go @@ -18,10 +18,10 @@ import ( "os" "testing" - "github.com/stretchr/testify/assert" "github.com/goharbor/harbor/src/common/models" errutil "github.com/goharbor/harbor/src/common/utils/error" "github.com/goharbor/harbor/src/common/utils/test" + "github.com/stretchr/testify/assert" ) func TestMain(m *testing.M) { diff --git a/src/ui/promgr/promgr_test.go b/src/ui/promgr/promgr_test.go index 51ed38afb..0fb9ef0f3 100644 --- a/src/ui/promgr/promgr_test.go +++ b/src/ui/promgr/promgr_test.go @@ -17,10 +17,10 @@ package promgr import ( "testing" - "github.com/stretchr/testify/assert" - "github.com/stretchr/testify/require" "github.com/goharbor/harbor/src/common/models" "github.com/goharbor/harbor/src/ui/promgr/pmsdriver" + "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/require" ) type fakePMSDriver struct { diff --git a/src/ui/proxy/interceptor_test.go b/src/ui/proxy/interceptor_test.go index f81e61f23..faaf99a84 100644 --- a/src/ui/proxy/interceptor_test.go +++ b/src/ui/proxy/interceptor_test.go @@ -1,8 +1,6 @@ package proxy import ( - "github.com/stretchr/testify/assert" - "github.com/stretchr/testify/require" "github.com/goharbor/harbor/src/adminserver/client" "github.com/goharbor/harbor/src/common" "github.com/goharbor/harbor/src/common/dao" @@ -10,6 +8,8 @@ import ( notarytest "github.com/goharbor/harbor/src/common/utils/notary/test" utilstest "github.com/goharbor/harbor/src/common/utils/test" "github.com/goharbor/harbor/src/ui/config" + "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/require" "net/http" "net/http/httptest" diff --git a/src/ui/service/notifications/clair/handler.go b/src/ui/service/notifications/clair/handler.go index d00e2c0c0..27f3ab4cc 100644 --- a/src/ui/service/notifications/clair/handler.go +++ b/src/ui/service/notifications/clair/handler.go @@ -46,7 +46,7 @@ func (h *Handler) Handle() { if clairClient == nil { clairClient = clair.NewClient(config.ClairEndpoint(), nil) } - var ne models.ClairNotificationEnvelope + var ne models.ClairNotificationEnvelope if err := json.Unmarshal(h.Ctx.Input.CopyBody(1<<32), &ne); err != nil { log.Errorf("Failed to decode the request: %v", err) return @@ -88,7 +88,7 @@ func (h *Handler) Handle() { return } for _, e := range l { - if err := clair.UpdateScanOverview(e.Digest, e.DetailsKey,config.ClairEndpoint()); err != nil { + if err := clair.UpdateScanOverview(e.Digest, e.DetailsKey, config.ClairEndpoint()); err != nil { log.Errorf("Failed to refresh scan overview for image: %s", e.Digest) } else { log.Debugf("Refreshed scan overview for record with digest: %s", e.Digest) diff --git a/src/ui/service/token/token_test.go b/src/ui/service/token/token_test.go index 1fc78a338..812c37f5b 100644 --- a/src/ui/service/token/token_test.go +++ b/src/ui/service/token/token_test.go @@ -56,42 +56,42 @@ func TestMain(m *testing.M) { func TestGetResourceActions(t *testing.T) { cases := map[string]*token.ResourceActions{ - "::": &token.ResourceActions{ + "::": { Type: "", Name: "", Actions: []string{}, }, - "repository": &token.ResourceActions{ + "repository": { Type: "repository", Name: "", Actions: []string{}, }, - "repository:": &token.ResourceActions{ + "repository:": { Type: "repository", Name: "", Actions: []string{}, }, - "repository:library/hello-world": &token.ResourceActions{ + "repository:library/hello-world": { Type: "repository", Name: "library/hello-world", Actions: []string{}, }, - "repository:library/hello-world:": &token.ResourceActions{ + "repository:library/hello-world:": { Type: "repository", Name: "library/hello-world", Actions: []string{}, }, - "repository:library/hello-world:pull,push": &token.ResourceActions{ + "repository:library/hello-world:pull,push": { Type: "repository", Name: "library/hello-world", Actions: []string{"pull", "push"}, }, - "registry:catalog:*": &token.ResourceActions{ + "registry:catalog:*": { Type: "registry", Name: "catalog", Actions: []string{"*"}, }, - "repository:192.168.0.1:443/library/hello-world:pull,push": &token.ResourceActions{ + "repository:192.168.0.1:443/library/hello-world:pull,push": { Type: "repository", Name: "192.168.0.1:443/library/hello-world", Actions: []string{"pull", "push"}, @@ -135,7 +135,7 @@ func TestMakeToken(t *testing.T) { pk, crt := getKeyAndCertPath() //overwrite the config values for testing. privateKey = pk - ra := []*token.ResourceActions{&token.ResourceActions{ + ra := []*token.ResourceActions{{ Type: "repository", Name: "10.117.4.142/notary-test/hello-world-2", Actions: []string{"pull", "push"}, @@ -193,10 +193,10 @@ func TestInit(t *testing.T) { } func TestBasicParser(t *testing.T) { - testList := []parserTestRec{parserTestRec{"library/ubuntu:14.04", image{"library", "ubuntu", "14.04"}, false}, - parserTestRec{"test/hello", image{"test", "hello", ""}, false}, - parserTestRec{"myimage:14.04", image{}, true}, - parserTestRec{"org/team/img", image{"org", "team/img", ""}, false}, + testList := []parserTestRec{{"library/ubuntu:14.04", image{"library", "ubuntu", "14.04"}, false}, + {"test/hello", image{"test", "hello", ""}, false}, + {"myimage:14.04", image{}, true}, + {"org/team/img", image{"org", "team/img", ""}, false}, } p := &basicParser{} @@ -215,12 +215,12 @@ func TestEndpointParser(t *testing.T) { p := &endpointParser{ "10.117.4.142:5000", } - testList := []parserTestRec{parserTestRec{"10.117.4.142:5000/library/ubuntu:14.04", image{"library", "ubuntu", "14.04"}, false}, - parserTestRec{"myimage:14.04", image{}, true}, - parserTestRec{"10.117.4.142:80/library/myimage:14.04", image{}, true}, - parserTestRec{"library/myimage:14.04", image{}, true}, - parserTestRec{"10.117.4.142:5000/myimage:14.04", image{}, true}, - parserTestRec{"10.117.4.142:5000/org/team/img", image{"org", "team/img", ""}, false}, + testList := []parserTestRec{{"10.117.4.142:5000/library/ubuntu:14.04", image{"library", "ubuntu", "14.04"}, false}, + {"myimage:14.04", image{}, true}, + {"10.117.4.142:80/library/myimage:14.04", image{}, true}, + {"library/myimage:14.04", image{}, true}, + {"10.117.4.142:5000/myimage:14.04", image{}, true}, + {"10.117.4.142:5000/org/team/img", image{"org", "team/img", ""}, false}, } for _, rec := range testList { r, err := p.parse(rec.input)