From dc72008f1e84e023a6b4a7727d397f8742d60b4e Mon Sep 17 00:00:00 2001 From: Massimiliano Pippi Date: Wed, 5 Jun 2019 20:55:48 +0200 Subject: [PATCH 1/3] define test as integration, add unit test case --- auth/auth_test.go | 20 ++++++++++++++------ 1 file changed, 14 insertions(+), 6 deletions(-) diff --git a/auth/auth_test.go b/auth/auth_test.go index 6a17655851e..26989532d0a 100644 --- a/auth/auth_test.go +++ b/auth/auth_test.go @@ -19,13 +19,13 @@ package auth_test import ( "encoding/json" - "flag" "io/ioutil" "net/http" "os" "testing" "github.com/arduino/arduino-cli/auth" + "github.com/stretchr/testify/require" ) var ( @@ -33,12 +33,20 @@ var ( testPass = os.Getenv("TEST_PASSWORD") ) -func TestMain(m *testing.M) { - flag.Parse() - os.Exit(m.Run()) +func TestNewConfig(t *testing.T) { + conf := auth.New() + require.Equal(t, "https://hydra.arduino.cc/oauth2/auth", conf.CodeURL) + require.Equal(t, "https://hydra.arduino.cc/oauth2/token", conf.TokenURL) + require.Equal(t, "cli", conf.ClientID) + require.Equal(t, "http://localhost:5000", conf.RedirectURI) + require.Equal(t, "profile:core offline", conf.Scopes) } -func TestToken(t *testing.T) { +func TestTokenIntegration(t *testing.T) { + if testing.Short() { + t.Skip("skip integration test") + } + if testUser == "" || testPass == "" { t.Skip("Skipped because user and pass were not provided") } @@ -49,7 +57,7 @@ func TestToken(t *testing.T) { } // Obtain info - req, err := http.NewRequest("GET", "https://auth.arduino.cc/v1/users/byID/me", nil) + req, err := http.NewRequest("GET", "https://ddauth.arduino.cc/v1/users/byID/me", nil) if err != nil { t.Fatal(err) } From a27cd0cebb1e440c21237c95f61ba5f8014ef404 Mon Sep 17 00:00:00 2001 From: Massimiliano Pippi Date: Wed, 5 Jun 2019 20:56:11 +0200 Subject: [PATCH 2/3] use task to run tests --- Taskfile.yml | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) create mode 100644 Taskfile.yml diff --git a/Taskfile.yml b/Taskfile.yml new file mode 100644 index 00000000000..9cf78a338ba --- /dev/null +++ b/Taskfile.yml @@ -0,0 +1,23 @@ +version: '2' + +tasks: + build: + desc: Build the project + cmds: + - go build -v -i + + test: + desc: Run the full testsuite + cmds: + - task: test-unit + - task: test-integration + + test-unit: + desc: Run unit tests only + cmds: + - go test -short {{ default "-v" .GOFLAGS }} {{ default "./..." .TARGETS }} + + test-integration: + desc: Run integration tests only + cmds: + - go test -run Integration {{ default "-v" .GOFLAGS }} {{ default "./..." .TARGETS }} From c5887eefe6c85537f97ae6c6f75a656a37f2a13f Mon Sep 17 00:00:00 2001 From: Massimiliano Pippi Date: Thu, 6 Jun 2019 17:33:25 +0200 Subject: [PATCH 3/3] fix typo --- auth/auth_test.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/auth/auth_test.go b/auth/auth_test.go index 26989532d0a..842f782df98 100644 --- a/auth/auth_test.go +++ b/auth/auth_test.go @@ -57,7 +57,7 @@ func TestTokenIntegration(t *testing.T) { } // Obtain info - req, err := http.NewRequest("GET", "https://ddauth.arduino.cc/v1/users/byID/me", nil) + req, err := http.NewRequest("GET", "https://auth.arduino.cc/v1/users/byID/me", nil) if err != nil { t.Fatal(err) }