You are an expert in writing code in many different languages. Your goal is to perform code completion for the following code, keeping in mind the rest of the code and the file meta data.
    Metadata details:
    filename: toggles_gen_test.go
    path of file: ./repos/grafana/pkg/services/featuremgmt
    
    the code of the file until where you have to start completion: package featuremgmt

import (
	"bytes"
	"encoding/csv"
	"encoding/json"
	"fmt"
	"html/template"
	"log"
	"os"
	"path/filepath"
	"strconv"
	"strings"
	"testing"
	"time"

	"github.com/google/go-cmp/cmp"
	"github.com/olekukonko/tablewriter"
	"github.com/stretchr/testify/require"
	v1 "k8s.io/apimachinery/pkg/apis/meta/v1"

	featuretoggleapi "github.com/grafana/grafana/pkg/apis/featuretoggle/v0alpha1"
	"github.com/grafana/grafana/pkg/services/apiserver/utils"
	"github.com/grafana/grafana/pkg/services/featuremgmt/strcase"
)

func TestFeatureToggleFiles(t *testing.T) {
	legacyNames := map[string]bool{
		"live-service-web-worker": true,
	}

	t.Run("check registry constraints", func(t *testing.T) {
		invalidNames := make([]string, 0)

		// Check that all flags set in code are valid
		for _, flag := range standardFeatureFlags {
			if flag.Expression == "true" && !(flag.Stage == FeatureStageGeneralAvailability || flag.Stage == FeatureStageDeprecated) {
				t.Errorf("only FeatureStageGeneralAvailability or FeatureStageDeprecated features can be enabled by default.  See: %s", flag.Name)
			}
			if flag.RequiresDevMode && flag.Stage != FeatureStageExperimental {
				t.Errorf("only alpha features can require dev mode.  See: %s", flag.Name)
			}
			if flag.Stage == FeatureStageUnknown {
				t.Errorf("standard toggles should not have an unknown state.  See: %s", flag.Name)
			}
			if flag.Description != strings.TrimSpace(flag.Description) {
				t.Errorf("flag Description should not start/end with spaces.  See: %s", flag.Name)
			}
			if flag.Name != strings.TrimSpace(flag.Name) {
				t.Errorf("flag Name should not start/end with spaces.  See: %s", flag.Name)
			}
			if flag.AllowSelfServe && !(flag.Stage == FeatureStageGeneralAvailability || flag.Stage == FeatureStagePublicPreview || flag.Stage == FeatureStageDeprecated) {
				t.Errorf("only allow self-serving GA, PublicPreview and Deprecated toggles")
			}
			if flag.Owner == "" {
				t.Errorf("feature %s does not have an owner. please fill the FeatureFlag.Owner property", flag.Name)
			}
			// Check camel case names
			if flag.Name != strcase.ToLowerCamel(flag.Name) && !legacyNames[flag.Name] {
				invalidNames = append(invalidNames, flag.Name)
			}
		}

		// Make sure the names are valid
		require.Empty(t, invalidNames, "%s feature names should be camel cased", invalidNames)
		// acronyms can be configured as needed via `ConfigureAcronym` function from `./strcase/camel.go`

		// Now that we know they are valid, update the json database
		t.Run("update k8s resource list", func(t *testing.T) {
			created := v1.NewTime(time.Now().UTC())
			resourceVersion := fmt.Sprintf("%d", created.UnixMilli())

			featuresFile := "toggles_gen.json"
			current := featuretoggleapi.FeatureList{
				TypeMeta: v1.TypeMeta{
					Kind:       "FeatureList",
					APIVersion: featuretoggleapi.APIVERSION,
				},
			}
			existing := featuretoggleapi.FeatureList{}
			body, err := os.ReadFile(featuresFile)
			if err == nil {
				_ = json.Unmarshal(body, &existing)
				current.ListMeta = existing.ListMeta
			}

			lookup := map[string]featuretoggleapi.FeatureSpec{}
			for _, flag := range standardFeatureFlags {
				lookup[flag.Name] = featuretoggleapi.FeatureSpec{
					Description:       flag.Description,
					Stage:             flag.Stage.String(),
					Owner:             string(flag.Owner),
					RequiresDevMode:   flag.RequiresDevMode,
					FrontendOnly:      flag.FrontendOnly,
					RequiresRestart:   flag.RequiresRestart,
					AllowSelfServe:    flag.AllowSelfServe,
					HideFromAdminPage: flag.HideFromAdminPage,
					HideFromDoc
    
func TestFeatureToggleFiles(t *testing.T) {
	legacyNames := map[string]bool{
		"live-service-web-worker": true,
	}

	t.Run("check registry constraints", func(t *testing.T) {
		invalidNames := make([]string, 0)

		// Check that all flags set in code are valid
		for _, flag := range standardFeatureFlags {
			if flag.Expression == "true" && !(flag.Stage == FeatureStageGeneralAvailability || flag.Stage == FeatureStageDeprecated) {
				t.Errorf("only FeatureStageGeneralAvailability or FeatureStageDeprecated features can be enabled by default.  See: %s", flag.Name)
			}
			if flag.RequiresDevMode && flag.Stage != FeatureStageExperimental {
				t.Errorf("only alpha features can require dev mode.  See: %s", flag.Name)
			}
			if flag.Stage == FeatureStageUnknown {
				t.Errorf("standard toggles should not have an unknown state.  See: %s", flag.Name)
			}
			if flag.Description != strings.TrimSpace(flag.Description) {
				t.Errorf("flag Description should not start/end with spaces.  See: %s", flag.Name)
			}
			if flag.Name != strings.TrimSpace(flag.Name) {
				t.Errorf("flag Name should not start/end with spaces.  See: %s", flag.Name)
			}
			if flag.AllowSelfServe && !(flag.Stage == FeatureStageGeneralAvailability || flag.Stage == FeatureStagePublicPreview || flag.Stage == FeatureStageDeprecated) {
				t.Errorf("only allow self-serving GA, PublicPreview and Deprecated toggles")
			}
			if flag.Owner == "" {
				t.Errorf("feature %s does not have an owner. please fill the FeatureFlag.Owner property", flag.Name)
			}
			// Check camel case names
			if flag.Name != strcase.ToLowerCamel(flag.Name) && !legacyNames[flag.Name] {
				invalidNames = append(invalidNames, flag.Name)
			}
		}

		// Make sure the names are valid
		require.Empty(t, invalidNames, "%s feature names should be camel cased", invalidNames)
		// acronyms can be configured as needed via `ConfigureAcronym` function from `./strcase/camel.go`

		// Now that we know they are valid, update the json database
		t.Run("update k8s resource list", func(t *testing.T) {
			created := v1.NewTime(time.Now().UTC())
			resourceVersion := fmt.Sprintf("%d", created.UnixMilli())

			featuresFile := "toggles_gen.json"
			current := featuretoggleapi.FeatureList{
				TypeMeta: v1.TypeMeta{
					Kind:       "FeatureList",
					APIVersion: featuretoggleapi.APIVERSION,
				},
			}
			existing := featuretoggleapi.FeatureList{}
			body, err := os.ReadFile(featuresFile)
			if err == nil {
				_ = json.Unmarshal(body, &existing)
				current.ListMeta = existing.ListMeta
			}

			lookup := map[string]featuretoggleapi.FeatureSpec{}
			for _, flag := range standardFeatureFlags {
				lookup[flag.Name] = featuretoggleapi.FeatureSpec{
					Description:       flag.Description,
					Stage:             flag.Stage.String(),
					Owner:             string(flag.Owner),
					RequiresDevMode:   flag.RequiresDevMode,
					FrontendOnly:      flag.FrontendOnly,
					RequiresRestart:   flag.RequiresRestart,
					AllowSelfServe:    flag.AllowSelfServe,
					HideFromAdminPage: flag.HideFromAdminPage,
					HideFromDocs:      flag.HideFromDocs,
					// EnabledVersion: ???,
				}

				// Replace them all
				// current.Items = append(current.Items, featuretoggleapi.Feature{
				// 	ObjectMeta: v1.ObjectMeta{
				// 		Name:              flag.Name,
				// 		CreationTimestamp: v1.NewTime(flag.Created),
				// 		ResourceVersion:   fmt.Sprintf("%d", flag.Created.UnixMilli()),
				// 	},
				// 	Spec: lookup[flag.Name],
				// })
				// current.ListMeta.ResourceVersion = resourceVersion
			}

			// Check for changes in any existing values
			for _, item := range existing.Items {
				v, ok := lookup[item.Name]
				if ok {
					delete(lookup, item.Name)
					a, e1 := json.Marshal(v)
					b, e2 := json.Marshal(item.Spec)
					if e1 != nil || e2 != nil || !bytes.Equal(a, b) {
						item.ResourceVersion = resourceVersion
						if item.Annotations == nil {
							item.Annotations = make(map[string]string)
						}
						item.Annotations[utils.AnnoKeyUpdatedTimestamp] = created.String()
						item.Spec = v // the current value
					}
				} else if item.DeletionTimestamp == nil {
					item.DeletionTimestamp = &created
					fmt.Printf("mark feature as deleted")
				}
				current.Items = append(current.Items, item)
			}

			// New flags not in the existing list
			for k, v := range lookup {
				current.Items = append(current.Items, featuretoggleapi.Feature{
					ObjectMeta: v1.ObjectMeta{
						Name:              k,
						CreationTimestamp: created,
						ResourceVersion:   fmt.Sprintf("%d", created.UnixMilli()),
					},
					Spec: v,
				})
			}

			out, err := json.MarshalIndent(current, "", "  ")
			require.NoError(t, err)

			err = os.WriteFile(featuresFile, out, 0644)
			require.NoError(t, err, "error writing file")
		})
	})

	t.Run("verify files", func(t *testing.T) {
		// Typescript files
		verifyAndGenerateFile(t,
			"../../../packages/grafana-data/src/types/featureToggles.gen.ts",
			generateTypeScript(),
		)

		// Golang files
		verifyAndGenerateFile(t,
			"toggles_gen.go",
			generateRegistry(t),
		)

		// Docs files
		verifyAndGenerateFile(t,
			"../../../docs/sources/setup-grafana/configure-grafana/feature-toggles/index.md",
			generateDocsMD(),
		)

		// CSV Analytics
		verifyAndGenerateFile(t,
			"toggles_gen.csv",
			generateCSV(),
		)
	})
}