Skip to content

Use go embed for readbility #3200

@sivchari

Description

@sivchari

This is a WIP which I want to do about this issue.

kubernetes/kubernetes#131774

Currently, some test code prepares test-data as a raw byte variable. These code are not supported by LSP and it's a little hard to read test-data.
After Go1.16, we can use embed function to embed files in Go code. This results in that we can separate test-data and test-code, then test-data is supported by native LSP.

But I'm concerning about the formatted code.
Here is the example.

https://github.com/kubernetes/kubernetes/blob/master/cmd/kubeadm/app/util/config/cluster_test.go#L50

Regarding above code, we can automatically migrate to minimum control plane version, but if these codes like this converts to embedded way, we should migrate manually from now on, then I think it's not good in term of maintaining.

So I propose the 2 rule.

  • Basically, it's prefer to use go:embed if you want to prepare the test-data
  • But, if the test data you prepare plan to be formatted, it's prefer to define as a raw byte string on Go file.

What do you think ?

Metadata

Metadata

Assignees

Labels

kind/cleanupCategorizes issue or PR as related to cleaning up code, process, or technical debt.priority/backlogHigher priority than priority/awaiting-more-evidence.

Type

No type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions