atghelper

package
v1.0.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Mar 2, 2023 License: Apache-2.0 Imports: 24 Imported by: 0

Documentation

Overview

* Copyright 2022 ByteDance Inc. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License.

* Copyright 2022 ByteDance Inc. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License.

* Copyright 2022 ByteDance Inc. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License.

* Copyright 2022 ByteDance Inc. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License.

* Copyright 2022 ByteDance Inc. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License.

* Copyright 2022 ByteDance Inc. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License.

* Copyright 2022 ByteDance Inc. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License.

Index

Constants

View Source
const (
	ID                    = "uuid_digit"
	HyphenatedID          = "uuid_hyphenated"
	EmailTag              = "email"
	MacAddressTag         = "mac_address"
	DomainNameTag         = "domain_name"
	UserNameTag           = "username"
	URLTag                = "url"
	IPV4Tag               = "ipv4"
	IPV6Tag               = "ipv6"
	PASSWORD              = "password"
	JWT                   = "jwt"
	LATITUDE              = "lat"
	LONGITUDE             = "long"
	CreditCardNumber      = "cc_number"
	CreditCardType        = "cc_type"
	PhoneNumber           = "phone_number"
	TollFreeNumber        = "toll_free_number"
	E164PhoneNumberTag    = "e_164_phone_number"
	TitleMaleTag          = "title_male"
	TitleFemaleTag        = "title_female"
	FirstNameTag          = "first_name"
	FirstNameMaleTag      = "first_name_male"
	FirstNameFemaleTag    = "first_name_female"
	LastNameTag           = "last_name"
	NAME                  = "name"
	GENDER                = "gender"
	UnixTimeTag           = "unix_time"
	DATE                  = "date"
	TIME                  = "time"
	MonthNameTag          = "month_name"
	YEAR                  = "year"
	DayOfWeekTag          = "day_of_week"
	DayOfMonthTag         = "day_of_month"
	TIMESTAMP             = "timestamp"
	CENTURY               = "century"
	TIMEZONE              = "timezone"
	TimePeriodTag         = "time_period"
	WORD                  = "word"
	SENTENCE              = "sentence"
	PARAGRAPH             = "paragraph"
	CurrencyTag           = "currency"
	AmountTag             = "amount"
	AmountWithCurrencyTag = "amount_with_currency"
	SKIP                  = "-"
	Length                = "len"
	SliceLength           = "slice_len"
	Language              = "lang"
	BoundaryStart         = "boundary_start"
	BoundaryEnd           = "boundary_end"
	Equals                = "="

	ONEOF = "oneof"
)

Supported tags

Variables

View Source
var (
	// LangENG is for english language
	LangENG = langRuneBoundary{65, 122, []rune{91, 92, 93, 94, 95, 96}}
	// LangCHI is for chinese language
	LangCHI = langRuneBoundary{19968, 40869, nil}
	// LangRUS is for russian language
	LangRUS = langRuneBoundary{1025, 1105, nil}
)

Language rune boundaries here

View Source
var (
	ErrUnsupportedKindPtr  = "Unsupported kind: %s Change Without using * (pointer) in Field of %s"
	ErrUnsupportedKind     = "Unsupported kind: %s"
	ErrValueNotPtr         = "Not a pointer value"
	ErrTagNotSupported     = "Tag unsupported: %s"
	ErrTagAlreadyExists    = "Tag exists"
	ErrTagDoesNotExist     = "Tag does not exist"
	ErrMoreArguments       = "Passed more arguments than is possible : (%d)"
	ErrNotSupportedPointer = "Use sample:=new(%s)\n faker.FakeData(sample) instead"
	ErrSmallerThanZero     = "Size:%d is smaller than zero."
	ErrSmallerThanOne      = "Size:%d is smaller than one."
	ErrUniqueFailure       = "Failed to generate a unique value for field \"%s\""

	ErrStartValueBiggerThanEnd = "Start value can not be bigger than end value."
	ErrWrongFormattedTag       = "Tag \"%s\" is not written properly"
	ErrUnknownType             = "Unknown Type"
	ErrNotSupportedTypeForTag  = "Type is not supported by tag."
	ErrUnsupportedTagArguments = "Tag arguments are not compatible with field type."
	ErrDuplicateSeparator      = "Duplicate separator for tag arguments."
	ErrNotEnoughTagArguments   = "Not enough arguments for tag."
	ErrUnsupportedNumberType   = "Unsupported Number type."
)

Generic Error Messages for tags

ErrUnsupportedKindPtr: Error when get fake from ptr
ErrUnsupportedKind: Error on passing unsupported kind
ErrValueNotPtr: Error when value is not pointer
ErrTagNotSupported: Error when tag is not supported
ErrTagAlreadyExists: Error when tag exists and call AddProvider
ErrTagDoesNotExist: Error when tag does not exist and call RemoveProvider
ErrMoreArguments: Error on passing more arguments
ErrNotSupportedPointer: Error when passing unsupported pointer
View Source
var EPSILON = 0.00000001
View Source
var GoKeywords = []string{
	"interface", "break", "default", "func", "select",
	"case", "defer", "go", "map", "struct",
	"chan", "else", "goto", "package", "switch",
	"const", "fallthrough", "if", "range ", "type",
	"continue", "for", "import", "return", "var"}
View Source
var MapperTag = mapperTag

Functions

func Contains

func Contains(slice []string, item string) bool

func DeepCopy

func DeepCopy(s string) string

func DeepCopySlice

func DeepCopySlice(bytes []byte) []byte

func FloatEquals

func FloatEquals(a, b float64) bool

func GetCurrentProjectRootPath

func GetCurrentProjectRootPath() string

func GetParentDirectory

func GetParentDirectory(dirctory string) string

func GetPkgName

func GetPkgName(path string) string

func GetPkgNameV2

func GetPkgNameV2(strExp string) string

get pkgname of reflect.Type

func GetRandomFloat

func GetRandomFloat() float64

func GetRepoByRelativePath

func GetRepoByRelativePath(relativePath string) string

func GetTheReceiveNameFromSSA

func GetTheReceiveNameFromSSA(s string) string

The receive name like:

var github.com/bytedance/nxt_unit/unittesttemplate.TikTokConsumption
var *github.com/bytedance/nxt_unit/unittesttemplate.TikTokConsumption

func GetUseMockByVersion

func GetUseMockByVersion(path string) int

func GetValue

func GetValue(t reflect.Type, level int) (reflect.Value, error)

It is only for ptr.

func IsBasicDataType

func IsBasicDataType(t string) bool

func IsExportByName

func IsExportByName(name string) bool

func IsFileExist

func IsFileExist(path string) bool

func IsSystemPkg

func IsSystemPkg(path string) bool

func IsTypeArray

func IsTypeArray(typ reflect.Type) bool

IsTypeArray returns if argument is array type

func IsTypeCollection

func IsTypeCollection(typ reflect.Type) bool

IsTypeCollection returns if the argument is a slice/array.

func IsTypeExported

func IsTypeExported(t reflect.Type) bool

func IsTypeFunction

func IsTypeFunction(typ reflect.Type) bool

IsTypeFunction returns if the argument is reflect.Func.

func IsTypeImplementsContext

func IsTypeImplementsContext(typ reflect.Type) bool

IsTypeImplementsContext returns if the argument is impl of context.Context

func IsTypeImplementsError

func IsTypeImplementsError(typ reflect.Type) bool

IsTypeImplementsError returns if the argument is impl of error

func IsTypeIteratee

func IsTypeIteratee(typ reflect.Type) bool

IsTypeIteratee returns if the argument is an iteratee.

func IsTypeMap

func IsTypeMap(typ reflect.Type) bool

IsTypeMap returns if the argument is a map

func IsTypeSlice

func IsTypeSlice(typ reflect.Type) bool

IsTypeSlice returns if argument is slice type

func IsValueNil

func IsValueNil(value reflect.Value) bool

IsValueNil returns if reflect.Value is nil. panics when value is invalid.

func LintPackageComment

func LintPackageComment(path string) ([]string, error)

get all comments

func RandStringBytes

func RandStringBytes(n int) string

func RandomBool

func RandomBool(rate float64) bool

func RandomFloat

func RandomFloat(min float64, max float64) float64

func RandomInt

func RandomInt(parameters ...int) (p []int, err error)

RandomInt Get three parameters , only first mandatory and the rest are optional

If only set one parameter :  This means the minimum number of digits and the total number
If only set two parameters : First this is min digit and second max digit and the total number the difference between them
If only three parameters: the third argument set Max count Digit

func RecoverOriginalFile

func RecoverOriginalFile(content []byte, path string) error

func RemoveCStyleComments

func RemoveCStyleComments(content []byte) []byte

func RemoveDirectory

func RemoveDirectory(dirName string)

func RemoveGoComments

func RemoveGoComments(path string) ([]byte, error)

func RemoveGoStyleComments

func RemoveGoStyleComments(content []byte, comments []string) []byte

func RemoveLastFilePath

func RemoveLastFilePath(s string) string

func RemoveTestCaseFile

func RemoveTestCaseFile(dirName, fileName string)

func ReplacePkgName

func ReplacePkgName(s string, pkgName string, originalPkgName string) string

func ReplacePkgNameForMap

func ReplacePkgNameForMap(s string, pkgName string, originalPkgName string, fromLeft bool) string

func UpperCaseFirstLetter

func UpperCaseFirstLetter(s string) string

UpperCaseFirstLetter won't change the input string.

Types

type GoVersionInfo

type GoVersionInfo struct {
	FirstLevel  int
	SecondLevel int
	ThirdLevel  int
}

func GetGoVersion

func GetGoVersion(path string) (GoVersionInfo, error)

type Plugin

type Plugin interface {
	InstructionFile() string
	AtgTestFile() string
}
var PluginSDK Plugin

func NewPluginSDK

func NewPluginSDK(instructionFile, atgTestFile string) Plugin

type RWLocker

type RWLocker interface {
	Lock() error
	Unlock() error
	RLock() error
	RUnlock() error
}
var GlobalFileLock RWLocker

type TaggedFunction

type TaggedFunction func(v reflect.Value) (interface{}, error)

TaggedFunction used as the standard layout function for tag providers in struct. This type also can be used for custom provider.

Directories

Path Synopsis
* Copyright 2022 ByteDance Inc.
* Copyright 2022 ByteDance Inc.
* Copyright 2022 ByteDance Inc.
* Copyright 2022 ByteDance Inc.
testase
user_security
* Copyright 2022 ByteDance Inc.
* Copyright 2022 ByteDance Inc.
* Copyright 2022 ByteDance Inc.
* Copyright 2022 ByteDance Inc.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL