We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Stakwork Run
File: /tmp/stakwork/sphinx-tribes/handlers/auth.go
package auth import ( "encoding/json" "net/http" "net/http/httptest" "testing" "github.com/stretchr/testify/assert" ) // Mock configuration for testing var config = struct { SuperAdmins interface{} }{} func TestGetAdminPubkeys(t *testing.T) { tests := []struct { name string superAdmins interface{} expectedStatus int expectedBody string }{ { name: "Standard Input with Multiple Admin Keys", superAdmins: []string{"key1", "key2", "key3"}, expectedStatus: http.StatusOK, expectedBody: `{"pubkeys":["key1","key2","key3"]}`, }, { name: "Standard Input with Single Admin Key", superAdmins: []string{"key1"}, expectedStatus: http.StatusOK, expectedBody: `{"pubkeys":["key1"]}`, }, { name: "Empty Admin Keys List", superAdmins: []string{}, expectedStatus: http.StatusOK, expectedBody: `{"pubkeys":[]}`, }, { name: "Maximum Number of Admin Keys", superAdmins: generateKeys(1000), expectedStatus: http.StatusOK, expectedBody: generateExpectedBody(1000), }, { name: "Null Admin Keys List", superAdmins: nil, expectedStatus: http.StatusOK, expectedBody: `{"pubkeys":null}`, }, { name: "Invalid Data Type for Admin Keys", superAdmins: "invalid_type", expectedStatus: http.StatusOK, expectedBody: `{"pubkeys":[]}`, }, { name: "Special Characters in Admin Keys", superAdmins: []string{"key1", "key@2", "key#3"}, expectedStatus: http.StatusOK, expectedBody: `{"pubkeys":["key1","key@2","key#3"]}`, }, { name: "Unicode Characters in Admin Keys", superAdmins: []string{"ключ1", "キー2", "钥匙3"}, expectedStatus: http.StatusOK, expectedBody: `{"pubkeys":["ключ1","キー2","钥匙3"]}`, }, } for _, tt := range tests { t.Run(tt.name, func(t *testing.T) { // Set the mock configuration config.SuperAdmins = tt.superAdmins // Create a request to pass to our handler req, err := http.NewRequest("GET", "/admin_pubkeys", nil) assert.NoError(t, err) // Create a ResponseRecorder to record the response rr := httptest.NewRecorder() handler := http.HandlerFunc(GetAdminPubkeys) // Call the handler handler.ServeHTTP(rr, req) // Check the status code assert.Equal(t, tt.expectedStatus, rr.Code) // Check the response body assert.JSONEq(t, tt.expectedBody, rr.Body.String()) }) } } // Helper function to generate a list of keys func generateKeys(n int) []string { keys := make([]string, n) for i := 0; i < n; i++ { keys[i] = "key" + string(i) } return keys } // Helper function to generate expected JSON body for a large number of keys func generateExpectedBody(n int) string { keys := generateKeys(n) jsonBytes, _ := json.Marshal(map[string][]string{"pubkeys": keys}) return string(jsonBytes) }
The text was updated successfully, but these errors were encountered:
@tomsmith8 assign me?
Sorry, something went wrong.
@tomsmith8 I can help?
@tomsmith8 please assign
@tomsmith8 can I help?
MuhammadUmer44
Successfully merging a pull request may close this issue.
Unit Test Coverage for "GetAdminPubkeys"
Stakwork Run
Unit Test Code
File: /tmp/stakwork/sphinx-tribes/handlers/auth.go
The text was updated successfully, but these errors were encountered: