...

Source file src/github.com/google/go-github/v47/github/packages_test.go

Documentation: github.com/google/go-github/v47/github

     1  // Copyright 2021 The go-github AUTHORS. All rights reserved.
     2  //
     3  // Use of this source code is governed by a BSD-style
     4  // license that can be found in the LICENSE file.
     5  
     6  package github
     7  
     8  import "testing"
     9  
    10  func TestPackageRegistry_Marshal(t *testing.T) {
    11  	testJSONMarshal(t, &PackageRegistry{}, "{}")
    12  
    13  	o := &PackageRegistry{
    14  		AboutURL: String("aurl"),
    15  		Name:     String("name"),
    16  		Type:     String("type"),
    17  		URL:      String("url"),
    18  		Vendor:   String("vendor"),
    19  	}
    20  	want := `{
    21  		"about_url": "aurl",
    22  		"name": "name",
    23  		"type": "type",
    24  		"url": "url",
    25  		"vendor": "vendor"
    26  	}`
    27  
    28  	testJSONMarshal(t, o, want)
    29  }
    30  
    31  func TestPackageFile_Marshal(t *testing.T) {
    32  	testJSONMarshal(t, &PackageFile{}, "{}")
    33  
    34  	o := &PackageFile{
    35  		DownloadURL: String("durl"),
    36  		ID:          Int64(1),
    37  		Name:        String("name"),
    38  		SHA256:      String("sha256"),
    39  		SHA1:        String("sha1"),
    40  		MD5:         String("md5"),
    41  		ContentType: String("ct"),
    42  		State:       String("state"),
    43  		Author: &User{
    44  			Login:           String("l"),
    45  			ID:              Int64(1),
    46  			URL:             String("u"),
    47  			AvatarURL:       String("a"),
    48  			GravatarID:      String("g"),
    49  			Name:            String("n"),
    50  			Company:         String("c"),
    51  			Blog:            String("b"),
    52  			Location:        String("l"),
    53  			Email:           String("e"),
    54  			Hireable:        Bool(true),
    55  			Bio:             String("b"),
    56  			TwitterUsername: String("t"),
    57  			PublicRepos:     Int(1),
    58  			Followers:       Int(1),
    59  			Following:       Int(1),
    60  			CreatedAt:       &Timestamp{referenceTime},
    61  			SuspendedAt:     &Timestamp{referenceTime},
    62  		},
    63  		Size:      Int64(1),
    64  		CreatedAt: &Timestamp{referenceTime},
    65  		UpdatedAt: &Timestamp{referenceTime},
    66  	}
    67  
    68  	want := `{
    69  		"download_url": "durl",
    70  		"id": 1,
    71  		"name": "name",
    72  		"sha256": "sha256",
    73  		"sha1": "sha1",
    74  		"md5": "md5",
    75  		"content_type": "ct",
    76  		"state": "state",
    77  		"author": {
    78  			"login": "l",
    79  			"id": 1,
    80  			"avatar_url": "a",
    81  			"gravatar_id": "g",
    82  			"name": "n",
    83  			"company": "c",
    84  			"blog": "b",
    85  			"location": "l",
    86  			"email": "e",
    87  			"hireable": true,
    88  			"bio": "b",
    89  			"twitter_username": "t",
    90  			"public_repos": 1,
    91  			"followers": 1,
    92  			"following": 1,
    93  			"created_at": ` + referenceTimeStr + `,
    94  			"suspended_at": ` + referenceTimeStr + `,
    95  			"url": "u"
    96  		},
    97  		"size": 1,
    98  		"created_at": ` + referenceTimeStr + `,
    99  		"updated_at": ` + referenceTimeStr + `
   100  	}`
   101  
   102  	testJSONMarshal(t, o, want)
   103  }
   104  
   105  func TestPackageRelease_Marshal(t *testing.T) {
   106  	testJSONMarshal(t, &PackageRelease{}, "{}")
   107  
   108  	o := &PackageRelease{
   109  		URL:             String("url"),
   110  		HTMLURL:         String("hurl"),
   111  		ID:              Int64(1),
   112  		TagName:         String("tn"),
   113  		TargetCommitish: String("tcs"),
   114  		Name:            String("name"),
   115  		Draft:           Bool(true),
   116  		Author: &User{
   117  			Login:           String("l"),
   118  			ID:              Int64(1),
   119  			URL:             String("u"),
   120  			AvatarURL:       String("a"),
   121  			GravatarID:      String("g"),
   122  			Name:            String("n"),
   123  			Company:         String("c"),
   124  			Blog:            String("b"),
   125  			Location:        String("l"),
   126  			Email:           String("e"),
   127  			Hireable:        Bool(true),
   128  			Bio:             String("b"),
   129  			TwitterUsername: String("t"),
   130  			PublicRepos:     Int(1),
   131  			Followers:       Int(1),
   132  			Following:       Int(1),
   133  			CreatedAt:       &Timestamp{referenceTime},
   134  			SuspendedAt:     &Timestamp{referenceTime},
   135  		},
   136  		Prerelease:  Bool(true),
   137  		CreatedAt:   &Timestamp{referenceTime},
   138  		PublishedAt: &Timestamp{referenceTime},
   139  	}
   140  
   141  	want := `{
   142  		"url": "url",
   143  		"html_url": "hurl",
   144  		"id": 1,
   145  		"tag_name": "tn",
   146  		"target_commitish": "tcs",
   147  		"name": "name",
   148  		"draft": true,
   149  		"author": {
   150  			"login": "l",
   151  			"id": 1,
   152  			"avatar_url": "a",
   153  			"gravatar_id": "g",
   154  			"name": "n",
   155  			"company": "c",
   156  			"blog": "b",
   157  			"location": "l",
   158  			"email": "e",
   159  			"hireable": true,
   160  			"bio": "b",
   161  			"twitter_username": "t",
   162  			"public_repos": 1,
   163  			"followers": 1,
   164  			"following": 1,
   165  			"created_at": ` + referenceTimeStr + `,
   166  			"suspended_at": ` + referenceTimeStr + `,
   167  			"url": "u"
   168  		},
   169  		"prerelease": true,
   170  		"created_at": ` + referenceTimeStr + `,
   171  		"published_at": ` + referenceTimeStr + `
   172  	}`
   173  
   174  	testJSONMarshal(t, o, want)
   175  }
   176  
   177  func TestPackageVersion_Marshal(t *testing.T) {
   178  	testJSONMarshal(t, &PackageVersion{}, "{}")
   179  
   180  	o := &PackageVersion{
   181  		ID:       Int64(1),
   182  		Version:  String("ver"),
   183  		Summary:  String("sum"),
   184  		Body:     String("body"),
   185  		BodyHTML: String("btnhtml"),
   186  		Release: &PackageRelease{
   187  			URL:             String("url"),
   188  			HTMLURL:         String("hurl"),
   189  			ID:              Int64(1),
   190  			TagName:         String("tn"),
   191  			TargetCommitish: String("tcs"),
   192  			Name:            String("name"),
   193  			Draft:           Bool(true),
   194  			Author: &User{
   195  				Login:           String("l"),
   196  				ID:              Int64(1),
   197  				URL:             String("u"),
   198  				AvatarURL:       String("a"),
   199  				GravatarID:      String("g"),
   200  				Name:            String("n"),
   201  				Company:         String("c"),
   202  				Blog:            String("b"),
   203  				Location:        String("l"),
   204  				Email:           String("e"),
   205  				Hireable:        Bool(true),
   206  				Bio:             String("b"),
   207  				TwitterUsername: String("t"),
   208  				PublicRepos:     Int(1),
   209  				Followers:       Int(1),
   210  				Following:       Int(1),
   211  				CreatedAt:       &Timestamp{referenceTime},
   212  				SuspendedAt:     &Timestamp{referenceTime},
   213  			},
   214  			Prerelease:  Bool(true),
   215  			CreatedAt:   &Timestamp{referenceTime},
   216  			PublishedAt: &Timestamp{referenceTime},
   217  		},
   218  		Manifest:        String("mani"),
   219  		HTMLURL:         String("hurl"),
   220  		TagName:         String("tn"),
   221  		TargetCommitish: String("tcs"),
   222  		TargetOID:       String("tid"),
   223  		Draft:           Bool(true),
   224  		Prerelease:      Bool(true),
   225  		CreatedAt:       &Timestamp{referenceTime},
   226  		UpdatedAt:       &Timestamp{referenceTime},
   227  		PackageFiles: []*PackageFile{
   228  			{
   229  				DownloadURL: String("durl"),
   230  				ID:          Int64(1),
   231  				Name:        String("name"),
   232  				SHA256:      String("sha256"),
   233  				SHA1:        String("sha1"),
   234  				MD5:         String("md5"),
   235  				ContentType: String("ct"),
   236  				State:       String("state"),
   237  				Author: &User{
   238  					Login:           String("l"),
   239  					ID:              Int64(1),
   240  					URL:             String("u"),
   241  					AvatarURL:       String("a"),
   242  					GravatarID:      String("g"),
   243  					Name:            String("n"),
   244  					Company:         String("c"),
   245  					Blog:            String("b"),
   246  					Location:        String("l"),
   247  					Email:           String("e"),
   248  					Hireable:        Bool(true),
   249  					Bio:             String("b"),
   250  					TwitterUsername: String("t"),
   251  					PublicRepos:     Int(1),
   252  					Followers:       Int(1),
   253  					Following:       Int(1),
   254  					CreatedAt:       &Timestamp{referenceTime},
   255  					SuspendedAt:     &Timestamp{referenceTime},
   256  				},
   257  				Size:      Int64(1),
   258  				CreatedAt: &Timestamp{referenceTime},
   259  				UpdatedAt: &Timestamp{referenceTime},
   260  			},
   261  		},
   262  		Author: &User{
   263  			Login:           String("l"),
   264  			ID:              Int64(1),
   265  			URL:             String("u"),
   266  			AvatarURL:       String("a"),
   267  			GravatarID:      String("g"),
   268  			Name:            String("n"),
   269  			Company:         String("c"),
   270  			Blog:            String("b"),
   271  			Location:        String("l"),
   272  			Email:           String("e"),
   273  			Hireable:        Bool(true),
   274  			Bio:             String("b"),
   275  			TwitterUsername: String("t"),
   276  			PublicRepos:     Int(1),
   277  			Followers:       Int(1),
   278  			Following:       Int(1),
   279  			CreatedAt:       &Timestamp{referenceTime},
   280  			SuspendedAt:     &Timestamp{referenceTime},
   281  		},
   282  		InstallationCommand: String("ic"),
   283  	}
   284  
   285  	want := `{
   286  		"id": 1,
   287  		"version": "ver",
   288  		"summary": "sum",
   289  		"body": "body",
   290  		"body_html": "btnhtml",
   291  		"release": {
   292  			"url": "url",
   293  			"html_url": "hurl",
   294  			"id": 1,
   295  			"tag_name": "tn",
   296  			"target_commitish": "tcs",
   297  			"name": "name",
   298  			"draft": true,
   299  			"author": {
   300  				"login": "l",
   301  				"id": 1,
   302  				"avatar_url": "a",
   303  				"gravatar_id": "g",
   304  				"name": "n",
   305  				"company": "c",
   306  				"blog": "b",
   307  				"location": "l",
   308  				"email": "e",
   309  				"hireable": true,
   310  				"bio": "b",
   311  				"twitter_username": "t",
   312  				"public_repos": 1,
   313  				"followers": 1,
   314  				"following": 1,
   315  				"created_at": ` + referenceTimeStr + `,
   316  				"suspended_at": ` + referenceTimeStr + `,
   317  				"url": "u"
   318  			},
   319  			"prerelease": true,
   320  			"created_at": ` + referenceTimeStr + `,
   321  			"published_at": ` + referenceTimeStr + `
   322  		},
   323  		"manifest": "mani",
   324  		"html_url": "hurl",
   325  		"tag_name": "tn",
   326  		"target_commitish": "tcs",
   327  		"target_oid": "tid",
   328  		"draft": true,
   329  		"prerelease": true,
   330  		"created_at": ` + referenceTimeStr + `,
   331  		"updated_at": ` + referenceTimeStr + `,
   332  		"package_files": [
   333  			{
   334  				"download_url": "durl",
   335  				"id": 1,
   336  				"name": "name",
   337  				"sha256": "sha256",
   338  				"sha1": "sha1",
   339  				"md5": "md5",
   340  				"content_type": "ct",
   341  				"state": "state",
   342  				"author": {
   343  					"login": "l",
   344  					"id": 1,
   345  					"avatar_url": "a",
   346  					"gravatar_id": "g",
   347  					"name": "n",
   348  					"company": "c",
   349  					"blog": "b",
   350  					"location": "l",
   351  					"email": "e",
   352  					"hireable": true,
   353  					"bio": "b",
   354  					"twitter_username": "t",
   355  					"public_repos": 1,
   356  					"followers": 1,
   357  					"following": 1,
   358  					"created_at": ` + referenceTimeStr + `,
   359  					"suspended_at": ` + referenceTimeStr + `,
   360  					"url": "u"
   361  				},
   362  				"size": 1,
   363  				"created_at": ` + referenceTimeStr + `,
   364  				"updated_at": ` + referenceTimeStr + `
   365  			}
   366  		],
   367  		"author": {
   368  			"login": "l",
   369  			"id": 1,
   370  			"avatar_url": "a",
   371  			"gravatar_id": "g",
   372  			"name": "n",
   373  			"company": "c",
   374  			"blog": "b",
   375  			"location": "l",
   376  			"email": "e",
   377  			"hireable": true,
   378  			"bio": "b",
   379  			"twitter_username": "t",
   380  			"public_repos": 1,
   381  			"followers": 1,
   382  			"following": 1,
   383  			"created_at": ` + referenceTimeStr + `,
   384  			"suspended_at": ` + referenceTimeStr + `,
   385  			"url": "u"
   386  		},
   387  		"installation_command": "ic"
   388  	}`
   389  
   390  	testJSONMarshal(t, o, want)
   391  }
   392  
   393  func TestPackage_Marshal(t *testing.T) {
   394  	testJSONMarshal(t, &Package{}, "{}")
   395  
   396  	o := &Package{
   397  		ID:          Int64(1),
   398  		Name:        String("name"),
   399  		PackageType: String("pt"),
   400  		HTMLURL:     String("hurl"),
   401  		CreatedAt:   &Timestamp{referenceTime},
   402  		UpdatedAt:   &Timestamp{referenceTime},
   403  		Visibility:  String("private"),
   404  		Owner: &User{
   405  			Login:           String("l"),
   406  			ID:              Int64(1),
   407  			URL:             String("u"),
   408  			AvatarURL:       String("a"),
   409  			GravatarID:      String("g"),
   410  			Name:            String("n"),
   411  			Company:         String("c"),
   412  			Blog:            String("b"),
   413  			Location:        String("l"),
   414  			Email:           String("e"),
   415  			Hireable:        Bool(true),
   416  			Bio:             String("b"),
   417  			TwitterUsername: String("t"),
   418  			PublicRepos:     Int(1),
   419  			Followers:       Int(1),
   420  			Following:       Int(1),
   421  			CreatedAt:       &Timestamp{referenceTime},
   422  			SuspendedAt:     &Timestamp{referenceTime},
   423  		},
   424  		PackageVersion: &PackageVersion{
   425  			ID:       Int64(1),
   426  			Version:  String("ver"),
   427  			Summary:  String("sum"),
   428  			Body:     String("body"),
   429  			BodyHTML: String("btnhtml"),
   430  			Release: &PackageRelease{
   431  				URL:             String("url"),
   432  				HTMLURL:         String("hurl"),
   433  				ID:              Int64(1),
   434  				TagName:         String("tn"),
   435  				TargetCommitish: String("tcs"),
   436  				Name:            String("name"),
   437  				Draft:           Bool(true),
   438  				Author: &User{
   439  					Login:           String("l"),
   440  					ID:              Int64(1),
   441  					URL:             String("u"),
   442  					AvatarURL:       String("a"),
   443  					GravatarID:      String("g"),
   444  					Name:            String("n"),
   445  					Company:         String("c"),
   446  					Blog:            String("b"),
   447  					Location:        String("l"),
   448  					Email:           String("e"),
   449  					Hireable:        Bool(true),
   450  					Bio:             String("b"),
   451  					TwitterUsername: String("t"),
   452  					PublicRepos:     Int(1),
   453  					Followers:       Int(1),
   454  					Following:       Int(1),
   455  					CreatedAt:       &Timestamp{referenceTime},
   456  					SuspendedAt:     &Timestamp{referenceTime},
   457  				},
   458  				Prerelease:  Bool(true),
   459  				CreatedAt:   &Timestamp{referenceTime},
   460  				PublishedAt: &Timestamp{referenceTime},
   461  			},
   462  			Manifest:        String("mani"),
   463  			HTMLURL:         String("hurl"),
   464  			TagName:         String("tn"),
   465  			TargetCommitish: String("tcs"),
   466  			TargetOID:       String("tid"),
   467  			Draft:           Bool(true),
   468  			Prerelease:      Bool(true),
   469  			CreatedAt:       &Timestamp{referenceTime},
   470  			UpdatedAt:       &Timestamp{referenceTime},
   471  			PackageFiles: []*PackageFile{
   472  				{
   473  					DownloadURL: String("durl"),
   474  					ID:          Int64(1),
   475  					Name:        String("name"),
   476  					SHA256:      String("sha256"),
   477  					SHA1:        String("sha1"),
   478  					MD5:         String("md5"),
   479  					ContentType: String("ct"),
   480  					State:       String("state"),
   481  					Author: &User{
   482  						Login:           String("l"),
   483  						ID:              Int64(1),
   484  						URL:             String("u"),
   485  						AvatarURL:       String("a"),
   486  						GravatarID:      String("g"),
   487  						Name:            String("n"),
   488  						Company:         String("c"),
   489  						Blog:            String("b"),
   490  						Location:        String("l"),
   491  						Email:           String("e"),
   492  						Hireable:        Bool(true),
   493  						Bio:             String("b"),
   494  						TwitterUsername: String("t"),
   495  						PublicRepos:     Int(1),
   496  						Followers:       Int(1),
   497  						Following:       Int(1),
   498  						CreatedAt:       &Timestamp{referenceTime},
   499  						SuspendedAt:     &Timestamp{referenceTime},
   500  					},
   501  					Size:      Int64(1),
   502  					CreatedAt: &Timestamp{referenceTime},
   503  					UpdatedAt: &Timestamp{referenceTime},
   504  				},
   505  			},
   506  			Author: &User{
   507  				Login:           String("l"),
   508  				ID:              Int64(1),
   509  				URL:             String("u"),
   510  				AvatarURL:       String("a"),
   511  				GravatarID:      String("g"),
   512  				Name:            String("n"),
   513  				Company:         String("c"),
   514  				Blog:            String("b"),
   515  				Location:        String("l"),
   516  				Email:           String("e"),
   517  				Hireable:        Bool(true),
   518  				Bio:             String("b"),
   519  				TwitterUsername: String("t"),
   520  				PublicRepos:     Int(1),
   521  				Followers:       Int(1),
   522  				Following:       Int(1),
   523  				CreatedAt:       &Timestamp{referenceTime},
   524  				SuspendedAt:     &Timestamp{referenceTime},
   525  			},
   526  			InstallationCommand: String("ic"),
   527  		},
   528  		Registry: &PackageRegistry{
   529  			AboutURL: String("aurl"),
   530  			Name:     String("name"),
   531  			Type:     String("type"),
   532  			URL:      String("url"),
   533  			Vendor:   String("vendor"),
   534  		},
   535  	}
   536  
   537  	want := `{
   538  		"id": 1,
   539  		"name": "name",
   540  		"package_type": "pt",
   541  		"html_url": "hurl",
   542  		"created_at": ` + referenceTimeStr + `,
   543  		"updated_at": ` + referenceTimeStr + `,
   544  		"visibility": "private",
   545  		"owner": {
   546  			"login": "l",
   547  			"id": 1,
   548  			"avatar_url": "a",
   549  			"gravatar_id": "g",
   550  			"name": "n",
   551  			"company": "c",
   552  			"blog": "b",
   553  			"location": "l",
   554  			"email": "e",
   555  			"hireable": true,
   556  			"bio": "b",
   557  			"twitter_username": "t",
   558  			"public_repos": 1,
   559  			"followers": 1,
   560  			"following": 1,
   561  			"created_at": ` + referenceTimeStr + `,
   562  			"suspended_at": ` + referenceTimeStr + `,
   563  			"url": "u"
   564  		},
   565  		"package_version": {
   566  			"id": 1,
   567  			"version": "ver",
   568  			"summary": "sum",
   569  			"body": "body",
   570  			"body_html": "btnhtml",
   571  			"release": {
   572  				"url": "url",
   573  				"html_url": "hurl",
   574  				"id": 1,
   575  				"tag_name": "tn",
   576  				"target_commitish": "tcs",
   577  				"name": "name",
   578  				"draft": true,
   579  				"author": {
   580  					"login": "l",
   581  					"id": 1,
   582  					"avatar_url": "a",
   583  					"gravatar_id": "g",
   584  					"name": "n",
   585  					"company": "c",
   586  					"blog": "b",
   587  					"location": "l",
   588  					"email": "e",
   589  					"hireable": true,
   590  					"bio": "b",
   591  					"twitter_username": "t",
   592  					"public_repos": 1,
   593  					"followers": 1,
   594  					"following": 1,
   595  					"created_at": ` + referenceTimeStr + `,
   596  					"suspended_at": ` + referenceTimeStr + `,
   597  					"url": "u"
   598  				},
   599  				"prerelease": true,
   600  				"created_at": ` + referenceTimeStr + `,
   601  				"published_at": ` + referenceTimeStr + `
   602  			},
   603  			"manifest": "mani",
   604  			"html_url": "hurl",
   605  			"tag_name": "tn",
   606  			"target_commitish": "tcs",
   607  			"target_oid": "tid",
   608  			"draft": true,
   609  			"prerelease": true,
   610  			"created_at": ` + referenceTimeStr + `,
   611  			"updated_at": ` + referenceTimeStr + `,
   612  			"package_files": [
   613  				{
   614  					"download_url": "durl",
   615  					"id": 1,
   616  					"name": "name",
   617  					"sha256": "sha256",
   618  					"sha1": "sha1",
   619  					"md5": "md5",
   620  					"content_type": "ct",
   621  					"state": "state",
   622  					"author": {
   623  						"login": "l",
   624  						"id": 1,
   625  						"avatar_url": "a",
   626  						"gravatar_id": "g",
   627  						"name": "n",
   628  						"company": "c",
   629  						"blog": "b",
   630  						"location": "l",
   631  						"email": "e",
   632  						"hireable": true,
   633  						"bio": "b",
   634  						"twitter_username": "t",
   635  						"public_repos": 1,
   636  						"followers": 1,
   637  						"following": 1,
   638  						"created_at": ` + referenceTimeStr + `,
   639  						"suspended_at": ` + referenceTimeStr + `,
   640  						"url": "u"
   641  					},
   642  					"size": 1,
   643  					"created_at": ` + referenceTimeStr + `,
   644  					"updated_at": ` + referenceTimeStr + `
   645  				}
   646  			],
   647  			"author": {
   648  				"login": "l",
   649  				"id": 1,
   650  				"avatar_url": "a",
   651  				"gravatar_id": "g",
   652  				"name": "n",
   653  				"company": "c",
   654  				"blog": "b",
   655  				"location": "l",
   656  				"email": "e",
   657  				"hireable": true,
   658  				"bio": "b",
   659  				"twitter_username": "t",
   660  				"public_repos": 1,
   661  				"followers": 1,
   662  				"following": 1,
   663  				"created_at": ` + referenceTimeStr + `,
   664  				"suspended_at": ` + referenceTimeStr + `,
   665  				"url": "u"
   666  			},
   667  			"installation_command": "ic"
   668  		},
   669  		"registry": {
   670  			"about_url": "aurl",
   671  			"name": "name",
   672  			"type": "type",
   673  			"url": "url",
   674  			"vendor": "vendor"
   675  		}
   676  	}`
   677  
   678  	testJSONMarshal(t, o, want)
   679  }
   680  

View as plain text