-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
7efbf4f
commit 2877278
Showing
15 changed files
with
194 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
package common | ||
|
||
import ( | ||
"github.com/stretchr/testify/assert" | ||
"testing" | ||
) | ||
|
||
func TestGetAddress(t *testing.T) { | ||
assert.True(t, len(GetAddress()) > 0) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
package common | ||
|
||
import ( | ||
"github.com/stretchr/testify/assert" | ||
"testing" | ||
) | ||
|
||
func TestRandomGenerator(t *testing.T) { | ||
b := "" | ||
for i := 1; i < 250; i++ { | ||
size := (i % 20) + 1 | ||
b = RandomString(size) | ||
assert.True(t, len(b) > 0) | ||
assert.Equal(t, size, len(b)) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
package ssl | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/stretchr/testify/assert" | ||
) | ||
|
||
func TestSSLGeneration(t *testing.T) { | ||
cert, pool, err := GenerateSelfSigned() | ||
|
||
assert.NoError(t, err) | ||
assert.NotNil(t, cert) | ||
assert.NotNil(t, pool) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
package main | ||
|
||
import ( | ||
"crypto/tls" | ||
"net/http" | ||
"testing" | ||
"time" | ||
|
||
"github.com/stretchr/testify/assert" | ||
) | ||
|
||
func TestApplicationBootOK(t *testing.T) { | ||
// given | ||
go main() | ||
time.Sleep(100 * time.Millisecond) | ||
|
||
// when | ||
resp, err := (&http.Client{ | ||
Transport: &http.Transport{ | ||
TLSClientConfig: &tls.Config{InsecureSkipVerify: true}, | ||
}, | ||
}).Get("https://127.0.0.1:3456/healthz") | ||
assert.NoError(t, err) | ||
assert.Equal(t, http.StatusOK, resp.StatusCode) | ||
|
||
// then | ||
srv.Close() | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
package main | ||
|
||
import ( | ||
"crypto/tls" | ||
"net/http" | ||
"testing" | ||
"time" | ||
|
||
"github.com/stretchr/testify/assert" | ||
) | ||
|
||
func TestApplicationBootOK(t *testing.T) { | ||
// given | ||
go main() | ||
time.Sleep(100 * time.Millisecond) | ||
|
||
// when | ||
resp, err := (&http.Client{ | ||
Transport: &http.Transport{ | ||
TLSClientConfig: &tls.Config{InsecureSkipVerify: true}, | ||
}, | ||
}).Get("http://127.0.0.1:8123/favicon.ico") | ||
assert.NoError(t, err) | ||
assert.Equal(t, http.StatusOK, resp.StatusCode) | ||
|
||
// then | ||
srv.Close() | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
package model | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/stretchr/testify/assert" | ||
) | ||
|
||
func TestServerState(t *testing.T) { | ||
// given | ||
s := ServerManager{} | ||
|
||
// when | ||
a, err := s.List() | ||
assert.NoError(t, err) | ||
// then | ||
assert.Equal(t, len(a), 0) | ||
|
||
// when | ||
err = s.Add("tenant", map[string]interface{}{"device": "test"}) | ||
assert.NoError(t, err) | ||
a, err = s.List() | ||
assert.NoError(t, err) | ||
// then | ||
assert.Equal(t, len(a), 1) | ||
|
||
// when | ||
s.Remove("tenant") | ||
a, err = s.List() | ||
assert.NoError(t, err) | ||
// then | ||
assert.Equal(t, len(a), 0) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
package view | ||
|
||
import ( | ||
"errors" | ||
"net/http" | ||
"net/http/httptest" | ||
"testing" | ||
|
||
"github.com/stretchr/testify/assert" | ||
) | ||
|
||
func TestErrorPageWithError(t *testing.T) { | ||
w := httptest.NewRecorder() | ||
ErrorPage(w, errors.New("__error__"), http.StatusTeapot) | ||
assert.Equal(t, http.StatusTeapot, w.Code) | ||
} | ||
|
||
func TestErrorPageWithoutError(t *testing.T) { | ||
w := httptest.NewRecorder() | ||
ErrorPage(w, nil, http.StatusTeapot) | ||
assert.Equal(t, http.StatusTeapot, w.Code) | ||
} |