fleet/server/service/integrationtest/android/android_test.go
Victor Lyuboslavsky faeb43f832
Scaffold for new integration tests. (#26747)
For #26219

Created a scaffold for server/service integration tests going forward.
- separate package
- no dependency on testify Suite
2025-03-04 12:04:25 -06:00

48 lines
1.4 KiB
Go

package android
import (
"net/http"
"testing"
"github.com/fleetdm/fleet/v4/server/datastore/mysql"
"github.com/fleetdm/fleet/v4/server/mdm/android"
"github.com/fleetdm/fleet/v4/server/service/integrationtest"
"github.com/stretchr/testify/assert"
)
func TestAndroid(t *testing.T) {
s := integrationtest.SetUpSuite(t, "integrationtest.Android")
cases := []struct {
name string
fn func(t *testing.T, s *integrationtest.Suite)
}{
{"HappyPath", testHappyPath},
}
for _, c := range cases {
t.Run(c.name, func(t *testing.T) {
defer mysql.TruncateTables(t, s.DS)
c.fn(t, s)
})
}
}
func testHappyPath(t *testing.T, s *integrationtest.Suite) {
signupDetails := expectSignupDetails(t, s)
var signupURL android.EnterpriseSignupResponse
s.DoJSON(t, "GET", "/api/v1/fleet/android_enterprise/signup_url", nil, http.StatusOK, &signupURL)
assert.Equal(t, signupURL.Url, signupDetails.Url)
}
func expectSignupDetails(t *testing.T, s *integrationtest.Suite) *android.SignupDetails {
signupDetails := &android.SignupDetails{
Url: "URL",
Name: "Name",
}
s.AndroidProxy.SignupURLsCreateFunc = func(callbackURL string) (*android.SignupDetails, error) {
// We will need to extract the security token from the callbackURL for further testing
assert.Contains(t, callbackURL, "/api/v1/fleet/android_enterprise/connect/")
return signupDetails, nil
}
return signupDetails
}