MCPcopy Create free account
hub / github.com/cloudbase/garm / TestCredentialsAndEndpointMigration

Function TestCredentialsAndEndpointMigration

database/sql/github_test.go:913–1052  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

911}
912
913func TestCredentialsAndEndpointMigration(t *testing.T) {
914 cfg := garmTesting.GetTestSqliteDBConfig(t)
915
916 // Copy the sample DB
917 data, err := os.ReadFile("../../testdata/db/v0.1.4/garm.db")
918 if err != nil {
919 t.Fatalf("failed to read test data: %s", err)
920 }
921
922 if cfg.SQLite.DBFile == "" {
923 t.Fatalf("DB file not set")
924 }
925 if err := os.WriteFile(cfg.SQLite.DBFile, data, 0o600); err != nil {
926 t.Fatalf("failed to write test data: %s", err)
927 }
928
929 // define some credentials
930 credentials := []config.Github{
931 {
932 Name: "test-creds",
933 Description: "test creds",
934 AuthType: config.GithubAuthTypePAT,
935 PAT: config.GithubPAT{
936 OAuth2Token: "test",
937 },
938 },
939 {
940 Name: "ghes-test",
941 Description: "ghes creds",
942 APIBaseURL: testAPIBaseURL,
943 UploadBaseURL: testUploadBaseURL,
944 BaseURL: testBaseURL,
945 AuthType: config.GithubAuthTypeApp,
946 App: config.GithubApp{
947 AppID: 1,
948 InstallationID: 99,
949 PrivateKeyPath: "../../testdata/certs/srv-key.pem",
950 },
951 },
952 }
953 // Set the config credentials in the cfg. This is what happens in the main function.
954 // of GARM as well.
955 cfg.MigrateCredentials = credentials
956
957 ctx := context.Background()
958 watcher.InitWatcher(ctx)
959 defer watcher.CloseWatcher()
960
961 db, err := NewSQLDatabase(ctx, cfg)
962 if err != nil {
963 t.Fatalf("failed to create db connection: %s", err)
964 }
965
966 // We expect that 2 endpoints will exist in the migrated DB and 2 credentials.
967 ctx = garmTesting.ImpersonateAdminContext(ctx, db, t)
968
969 endpoints, err := db.ListGithubEndpoints(ctx)
970 if err != nil {

Callers

nothing calls this directly

Calls 6

InitWatcherFunction · 0.92
CloseWatcherFunction · 0.92
NewSQLDatabaseFunction · 0.85
PrivateKeyBytesMethod · 0.80
ListGithubEndpointsMethod · 0.65
ListGithubCredentialsMethod · 0.65

Tested by

no test coverage detected