go.chromium.org/luci@v0.0.0-20240309015107-7cdc2e660f33/auth_service/internal/realmsinternals/fakecfgclient.go (about)

     1  // Copyright 2023 The LUCI Authors.
     2  //
     3  // Licensed under the Apache License, Version 2.0 (the "License");
     4  // you may not use this file except in compliance with the License.
     5  // You may obtain a copy of the License at
     6  //
     7  //	http://www.apache.org/licenses/LICENSE-2.0
     8  //
     9  // Unless required by applicable law or agreed to in writing, software
    10  // distributed under the License is distributed on an "AS IS" BASIS,
    11  // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    12  // See the License for the specific language governing permissions and
    13  // limitations under the License.
    14  
    15  package realmsinternals
    16  
    17  import (
    18  	"context"
    19  	"fmt"
    20  
    21  	"go.chromium.org/luci/config"
    22  )
    23  
    24  var testRevision = "test-revision"
    25  var testContentHash = "test-hash"
    26  
    27  var projectsWithCfg = map[string][]string{
    28  	RealmsDevCfgPath: {
    29  		"test-project-a",
    30  		"test-project-d",
    31  		CriaDev,
    32  	},
    33  }
    34  
    35  func testMeta(configSet config.Set) config.Meta {
    36  	return config.Meta{
    37  		ConfigSet:   configSet,
    38  		Path:        RealmsDevCfgPath,
    39  		ContentHash: testContentHash,
    40  		Revision:    testRevision,
    41  	}
    42  }
    43  
    44  type fakeCfgClient struct {
    45  	config.Interface
    46  }
    47  
    48  func (*fakeCfgClient) GetConfig(ctx context.Context, configSet config.Set, path string, metaOnly bool) (*config.Config, error) {
    49  	return &config.Config{Meta: testMeta(configSet)}, nil
    50  }
    51  
    52  func (*fakeCfgClient) GetProjectConfigs(ctx context.Context, path string, metaOnly bool) ([]config.Config, error) {
    53  	var configsToReturn []config.Config
    54  	if path == RealmsDevCfgPath {
    55  		for _, project := range projectsWithCfg[RealmsDevCfgPath] {
    56  			conf := config.Config{
    57  				Meta: config.Meta{
    58  					ConfigSet:   config.Set(fmt.Sprintf("projects/%s", project)),
    59  					Path:        path,
    60  					ContentHash: testContentHash,
    61  				},
    62  			}
    63  			if project == CriaDev {
    64  				conf.Meta.ConfigSet = CriaDev
    65  			}
    66  			configsToReturn = append(configsToReturn, conf)
    67  		}
    68  	}
    69  	return configsToReturn, nil
    70  }
    71  
    72  func (*fakeCfgClient) Close() error {
    73  	return nil
    74  }